Я хочу сделать переключатель, который меняет состояние моей кнопки Это первое состояние - по умолчанию
И второе состояние - когда мы нажимаем на него
Это их шаблон
<ControlTemplate x:Key="AddListTemplate">
<Grid>
<Button VerticalAlignment="Top"
HorizontalAlignment="Left"
Style="{StaticResource MaterialDesignOutlinedButton}"
ToolTip="MaterialDesignOutlinedButton"
Foreground="#5e6c84"
Name="AddListButton_false"
Command="{Binding ShowAddListButton}"
Margin="5 0"
Width="272"
>
+ Add another list
</Button>
<Border x:Name="AddListButton_true" CornerRadius="3" Width="272" MinHeight="78" VerticalAlignment="Top" Background="#ebecf0" Margin="8 0 4 0" Padding="4">
<StackPanel>
<Border CornerRadius="3" BorderThickness="2" Background="White" BorderBrush="#0079bf">
<TextBox Width="264"
materialDesign:HintAssist.Hint="Enter list title..."
BorderThickness="0"
Height="32" FontSize="16"
Padding="2 0" Background="Transparent"/>
</Border>
<StackPanel Orientation="Horizontal" Margin="0 4 0 0">
<Button Height="32" Background="#5AAC44" BorderBrush="Transparent"
materialDesign:ShadowAssist.ShadowDepth="Depth0">
Add List
</Button>
<Button
Style="{StaticResource MaterialDesignOutlinedButton}"
Command="{Binding HideAddListButton}"
ToolTip="MaterialDesignOutlinedButton"
Foreground="#5e6c84"
Height="32"
Margin="4 0"
>
Cancel
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsAddListTrigger, UpdateSourceTrigger=PropertyChanged}" Value="false">
<Setter TargetName="AddListButton_false" Property="Visibility" Value="Visible" />
<Setter TargetName="AddListButton_true" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsAddListTrigger, UpdateSourceTrigger=PropertyChanged}" Value="true">
<Setter TargetName="AddListButton_false" Property="Visibility" Value="Collapsed" />
<Setter TargetName="AddListButton_true" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Это работает правильно, но у меня проблемы с другими кнопками, у которых шаблон почти одинаковый, отличается только имя переменных
Их привязка данных не работает, и я не знаю почему. Важные части кода
Шаблоны
<Page.Resources>
<ControlTemplate x:Key="AddListTemplate">
<Grid>
<Button VerticalAlignment="Top"
HorizontalAlignment="Left"
Style="{StaticResource MaterialDesignOutlinedButton}"
ToolTip="MaterialDesignOutlinedButton"
Foreground="#5e6c84"
Name="AddListButton_false"
Command="{Binding ShowAddListButton}"
Margin="5 0"
Width="272"
>
+ Add another list
</Button>
<Border x:Name="AddListButton_true" CornerRadius="3" Width="272" MinHeight="78" VerticalAlignment="Top" Background="#ebecf0" Margin="8 0 4 0" Padding="4">
<StackPanel>
<Border CornerRadius="3" BorderThickness="2" Background="White" BorderBrush="#0079bf">
<TextBox Width="264"
materialDesign:HintAssist.Hint="Enter list title..."
BorderThickness="0"
Height="32" FontSize="16"
Padding="2 0" Background="Transparent"/>
</Border>
<StackPanel Orientation="Horizontal" Margin="0 4 0 0">
<Button Height="32" Background="#5AAC44" BorderBrush="Transparent"
materialDesign:ShadowAssist.ShadowDepth="Depth0">
Add List
</Button>
<Button
Style="{StaticResource MaterialDesignOutlinedButton}"
Command="{Binding HideAddListButton}"
ToolTip="MaterialDesignOutlinedButton"
Foreground="#5e6c84"
Height="32"
Margin="4 0"
>
Cancel
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsAddListTrigger, UpdateSourceTrigger=PropertyChanged}" Value="false">
<Setter TargetName="AddListButton_false" Property="Visibility" Value="Visible" />
<Setter TargetName="AddListButton_true" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsAddListTrigger, UpdateSourceTrigger=PropertyChanged}" Value="true">
<Setter TargetName="AddListButton_false" Property="Visibility" Value="Collapsed" />
<Setter TargetName="AddListButton_true" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="AddCardTemplate">
<Grid>
<Button
Style="{StaticResource MaterialDesignOutlinedButton}"
ToolTip="MaterialDesignOutlinedButton"
Command="{Binding ShowAddCardButton}"
Name="AddCardButton_false"
Foreground="#5e6c84"
Margin="7.2 5 7.2 5"
>
+ Add another card
</Button>
<Border x:Name="AddCardButton_true" CornerRadius="3" MinHeight="90" VerticalAlignment="Top" Background="#ebecf0" Margin="8 0 4 0" Padding="0 4 4 4">
<StackPanel>
<Border CornerRadius="3" MinHeight="44" Background="White" Padding="8 6 8 2">
<Border.Effect>
<DropShadowEffect BlurRadius="1.5" Color="LightGray" Direction="-90" RenderingBias="Quality" ShadowDepth="1"/>
</Border.Effect>
<TextBox Width="264"
materialDesign:HintAssist.Hint="Enter list title..."
BorderThickness="0"
Height="32" FontSize="16"
Padding="2 0" Background="Transparent"/>
</Border>
<StackPanel Orientation="Horizontal" Margin="0 4 0 0">
<Button Height="32" Background="#5AAC44" BorderBrush="Transparent"
materialDesign:ShadowAssist.ShadowDepth="Depth0">
Add List
</Button>
<Button
Style="{StaticResource MaterialDesignOutlinedButton}"
Command="{Binding HideAddCardButton}"
ToolTip="MaterialDesignOutlinedButton"
Foreground="#5e6c84"
Height="32"
Margin="4 0"
>
Cancel
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsAddCardTrigger, UpdateSourceTrigger=PropertyChanged}" Value="false">
<Setter TargetName="AddCardButton_false" Property="Visibility" Value="Visible" />
<Setter TargetName="AddCardButton_true" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsAddCardTrigger, UpdateSourceTrigger=PropertyChanged}" Value="true">
<Setter TargetName="AddCardButton_false" Property="Visibility" Value="Collapsed" />
<Setter TargetName="AddCardButton_true" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Page.Resources>
Переплет
<Grid Grid.Row="1" Margin="0 0 4 0">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" Margin="0 0 0 5">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left">
<ItemsControl ItemsSource="{Binding CurrentBoard.Lists}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0 0 0 20"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border CornerRadius="3" Width="272" MinHeight="78" VerticalAlignment="Top" Background="#ebecf0" Margin="8 0 4 0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="{Binding Title}" Foreground="#172b4d" FontSize="16"
FontWeight="DemiBold" TextWrapping="Wrap" Padding="8 10"/>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Cards}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border CornerRadius="3" MinHeight="44" Background="White" Margin="8 0 8 8" Padding="8 6 8 2">
<Border.Effect>
<DropShadowEffect BlurRadius="1.5" Color="LightGray" Direction="-90" RenderingBias="Quality" ShadowDepth="1"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="{Binding Title}" Foreground="#172b4d" FontSize="14" Margin="0 0 0 4"/>
</Grid>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
<Grid Grid.Row="2">
<ContentControl Content="{Binding}" Template="{DynamicResource AddCardTemplate}"/>
</Grid>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ContentControl Template="{StaticResource AddListTemplate}"/>
</StackPanel>
</ScrollViewer>
</Grid>