Need help with a C#/WPF/XAML problem
Posted: Wed Oct 05, 2022 10:52 am
I'm trying to implement an interface to manage the snapshots in IX Snapshot, the idea being that eventually you'll be able to see the actual values, copy them from one snapshot to another etc. The drop-downs above the treeviews select which snapshot to display, making SlotA or SlotB point to the desired source.

The tree items bind to a property 'GotValue' and if the snapshot has a value for that item, it will be bold. The problem is that I need to somehow tell GotValue which snapshot to use, SlotA or SlotB. Here's the XAML for the left combobox and treeview, the other side is pretty much identical...
Can anyone think of a way to get this working? My searches are bringing up stuff that's either irrelevant or so far beyond my knowledge that I can't tell whether it's relevant or not. The only thing I can think of is adding extra properties GotValueA and GotValueB but that will involve a lot of duplication (since GotValue is used for the main treeview too) and create a lot of new headaches. Really hoping for a simple and elegant solution. 

The tree items bind to a property 'GotValue' and if the snapshot has a value for that item, it will be bold. The problem is that I need to somehow tell GotValue which snapshot to use, SlotA or SlotB. Here's the XAML for the left combobox and treeview, the other side is pretty much identical...
Code: Select all
<ComboBox ItemsSource="{Binding Slots, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding SelA, Mode=TwoWay}">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding SlotA.HasData, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<!-- removed stuff for item content -->
</ComboBox>
<TreeView x:Name="ListA" ItemsSource="{Binding States, UpdateSourceTrigger=PropertyChanged}">
<TreeView.ItemContainerStyle>
<!-- This Style binds a TreeViewItem to a TreeViewItemViewModel. -->
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpandedM, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelectedM, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<!-- How can I select sanpshot A or B here? -->
<DataTrigger Binding="{Binding GotValue, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<!-- removed stuff for tree stucture -->
</TreeView>
