ok im all set this is the fix for the tag
Tag="{Binding BindsDirectlyToSource=True}"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I cant get the buttons to bind to the Btn_AddNewDataModel_Click relay command can anybody help and also i need to send the CommandParameter model back any suggestions
Thanks
Madaxe
<Grid>
<Expander Header="Software" IsExpanded="True">
<Grid Margin="40,10,0,0">
<ItemsControl ItemsSource="{Binding Path=Media_Model.Vendors}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Name}" Margin="0,0,0,20">
<Grid Margin="20,10,0,0">
<ItemsControl ItemsSource="{Binding Software}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}"
Width="100"
HorizontalAlignment="Left"
Margin="5,5,5,5"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, Path=Btn_AddNewDataModel_Click}"
CommandParameter="{Binding}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Expander>
</Grid>
public class SoftwareInstallViewModel
{
private string _ConfigurationXMLPath = @"M:\Nikola\SoftwareList.json";
public Media_Model Media_Model { get; set; } = null;
public RelayCommand Btn_AddNewDataModel_Click { get; private set; }
public SoftwareInstallViewModel()
{
LoadConfigurationXML();
Btn_AddNewDataModel_Click = new RelayCommand(AddNewDataModel, CanAddNewDataModel);
}
public void AddNewDataModel(object message)
{
}
public bool CanAddNewDataModel(object message)
{
return true;
}
private void LoadConfigurationXML()
{
using (StreamReader streamReader = new StreamReader(_ConfigurationXMLPath))
{
string json = streamReader.ReadToEnd();
Media_Model = JsonConvert.DeserializeObject<Media_Model>(json);
}
}
}
ok im all set this is the fix for the tag
Tag="{Binding BindsDirectlyToSource=True}"
I was able to resolve the binding issue by navigating the ancestor to the window, since the datacontext is at the window level this works, thanks for the hint.
I now want to bind the button tag the the Software model any ideas?
Thansk
Madaxe
<Window x:Class="Nikola_Software_Installation_App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Nikola_Software_Installation_App"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Expander Header="Software" IsExpanded="True">
<Grid Margin="40,10,0,0">
<ItemsControl ItemsSource="{Binding Path=Media_Model.Vendors}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Name}" Margin="0,0,0,20">
<Grid Margin="20,10,0,0">
<ItemsControl ItemsSource="{Binding Software}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}"
Width="100"
HorizontalAlignment="Left"
Margin="5,5,5,5"
Tag="{Binding Software}"
Command="{Binding DataContext.Btn_AddNewDataModel_Click, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Expander>
</Grid>
</Window>