I made a this
This is the xaml code
<TreeView ItemsSource="{Binding ViewModel.Crashes}"
SelectedItemChanged="TreeView_OnSelectedItemChanged"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Channels}">
<StackPanel Orientation="Horizontal" Margin="-10,0,0,0">
<CheckBox IsChecked="{Binding IsChecked }"/>
<TextBlock Text="{Binding Name }" Margin="-90,6,0,0"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate >
<DataTemplate DataType="{x:Type crashes:Channel}">
<StackPanel Orientation="Horizontal" Margin="-10,0,0,0" >
<CheckBox IsChecked="{Binding IsChecked }" />
<TextBlock Text="{Binding Name }" Margin="-90,6,0,0"/>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The code behind
public partial class Graph : INavigableView<GraphViewModel>
{
public GraphViewModel ViewModel
{
get;
}
public Graph(GraphViewModel viewModel)
{
ViewModel = viewModel;
InitializeComponent();
}
private void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
switch (e.NewValue)
{
case Channel channel:
ViewModel.SelectedChannel = channel;
break;
case Crash crash:
ViewModel.SelectedCrash = crash;
break;
}
}
}
The question is whether it is possible to put a command from the ViewModel in the checkbox. Something like this, but make the text above the red line in the checkbox the same as the article source.
If more information is needed, let me know and I will do my best to provide it.
UPDATE:
I changed the xaml for the checkbox to :
<CheckBox IsChecked="{Binding IsChecked }"
Command="{Binding DataContext.ViewModel.CheckChannelCommand,RelativeSource={RelativeSource AncestorType=TreeView}}"/>
but the command is never triggered.
For context this command in the checkbox works as expected
Here is the XAML code:
<ui:UiPage
x:Class="BDRv3.Views.Pages.Graph"
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:local="clr-namespace:BDRv3.Views.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:BDRv3.Models"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:windowsViewModels="clr-namespace:BDRv3.ViewModels.WindowsViewModels"
xmlns:pagesViewModels="clr-namespace:BDRv3.ViewModels.PagesViewModels"
xmlns:crashes="clr-namespace:BDRv3.Models.Crashes"
xmlns:oxy="http://oxyplot.org/wpf"
Title="Graph"
d:DataContext="{d:DesignInstance local:Graph,
IsDesignTimeCreatable=False}"
d:DesignHeight="450"
d:DesignWidth="800"
d:Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:Button Grid.Column="0" Icon="Edit48" ToolTip="Open" Command="{Binding ViewModel.OpenIsoFilesCommand }" Height="34" Margin="5,0,5,0" HorizontalAlignment="Stretch"/>
<ui:Button Grid.Column="1" Icon="Delete48" ToolTip="Clear" Height="34" Margin="0,0,5,0" HorizontalAlignment="Stretch"/>
<ui:Button Grid.Column="2" Icon="ClipboardTaskListRtl24" ToolTip="All in One" Height="34" Margin="0,0,5,0" HorizontalAlignment="Stretch"/>
<ui:Button Grid.Column="3" Icon="TableSimple48" ToolTip="Tiled" Height="34" Margin="0,0,5,0" HorizontalAlignment="Stretch"/>
<ui:Button Grid.Column="4" Icon="DataBarHorizontal24" ToolTip="Tabbed" Height="34" Margin="0,0,5,0" HorizontalAlignment="Stretch"/>
</Grid>
<ui:Card Grid.Column="0" Grid.Row="1"
Margin="5"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TreeView ItemsSource="{Binding ViewModel.Crashes}"
SelectedItemChanged="TreeView_OnSelectedItemChanged"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Channels}">
<StackPanel Orientation="Horizontal" Margin="-10,0,0,0">
<CheckBox IsChecked="{Binding IsChecked }"
Command="{Binding ViewModel.CheckChannelCommand,RelativeSource={RelativeSource AncestorType=TreeView}}"/>
<TextBlock Text="{Binding Name }" Margin="-90,6,0,0"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate >
<DataTemplate DataType="{x:Type crashes:Channel}">
<StackPanel Orientation="Horizontal" Margin="-10,0,0,0" >
<CheckBox IsChecked="{Binding IsChecked }" />
<TextBlock Text="{Binding Name }" Margin="-90,6,0,0"/>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Label Content="No Crash Files Imported"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="Gray">
<Label.Style>
<Style TargetType="Label">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding ViewModel.Crashes.Count}" Value="0">
<Setter Property="Visibility" Value="Visible"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</Grid>
</ui:Card>
<ui:Card Grid.Column="0" Grid.Row="2" VerticalAlignment="Stretch" Margin="5">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<CheckBox Command="{Binding ViewModel.CheckChannelCommand}"></CheckBox>
<Label VerticalAlignment="Center" Content="Sampling Rate" Margin="0 0 10 0"/>
<TextBox HorizontalContentAlignment="Center" MinWidth="50" MaxWidth="120" Text="{Binding ViewModel.SelectedChannel.SampleRate}"></TextBox>
</StackPanel>
</ui:Card>
<ui:Card Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" VerticalAlignment="Stretch" Margin="5" VerticalContentAlignment="Stretch">
<TabControl>
<TabItem Header="General" >
<oxy:PlotView Model="{Binding ViewModel.PlotModel}" >
<oxy:PlotView.DefaultTrackerTemplate>
<ControlTemplate>
<oxy:TrackerControl >
<oxy:TrackerControl.Content>
<TextBlock Text="{Binding}" Margin="7" Foreground="Black" />
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</oxy:PlotView.DefaultTrackerTemplate>
</oxy:PlotView>
</TabItem>
<TabItem Header="General"></TabItem>
<TabItem Header="General">
<TabControl>
<TabItem Header="General" >
</TabItem>
<TabItem Header="General"></TabItem>
<TabItem Header="General"></TabItem>
</TabControl>
</TabItem>
</TabControl>
</ui:Card>
</Grid>
</ui:UiPage>