Need help with a C#/WPF/XAML problem

Post Reply
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Need help with a C#/WPF/XAML problem

Post by IXix »

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.

Image

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>
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. :idea:
wde
Posts: 332
Joined: Sun Jan 08, 2012 9:28 am

Re: Need help with a C#/WPF/XAML problem

Post by wde »

Not sure if this works but you could create a helper

Code: Select all

	public class TreeHelper : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		public bool GotValue { get; set; }

		public TreeHelper(bool leftSide)
		{
			this.leftSide = leftSide;
		}
	...
And then create couple of these things to separate property events

Code: Select all

t1 = new TreeHelper(true);
t2 = new TreeHelper(false);

ListA.DataContext = t1;
ListB.DataContext = t2;
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: Need help with a C#/WPF/XAML problem

Post by IXix »

wde wrote: Wed Oct 05, 2022 4:52 pmNot sure if this works but you could create a helper...
Ah, thanks! I'll give that a try. Wish me luck! :lol:
Post Reply