0
我發現WPF和MVVM,我認爲我的問題可以幫助我很多在接下來的日子在我的項目上工作。WPF項目,與按鈕的側面菜單導航
硅這裏是我有:
所以:
- 每個按鈕打開窗口
- 激活鍵具有應用的右側視圖不同風格(如綠色背景)
要加載一個按鈕的按鈕,我不擔心,我會在我的網格onClick上添加一個特定的XAML。
但是爲了在活動按鈕上應用不同風格,我迷路了。 我是否設置了一個變量onClick和我的風格資源我將觸發器綁定到這個變量?我不是如何做到這一點。
我的主窗口被定義這樣的:
<Window x:Class="XXXX.UserInterface.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:XXXX.UserInterface"
mc:Ignorable="d"
Title="MainWindow"
Style="{StaticResource CustomWindowStyle}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource SideMenuBorder}">
<StackPanel Grid.Column="0" Orientation="Vertical">
<Button Click="ButtonCovertC_Click"
x:Name="ButtonCovertC"
Margin="5.5 9 8.5 0"
Style="{StaticResource ButtonSideMenu}"
Content="{local:Loc ButtonCovertC}"/>
<Button Click="ButtonEarpieceC_Click"
x:Name="ButtonEarpieceC"
Margin="5.5 14 8.5 0"
Style="{StaticResource ButtonSideMenu}"
Content="{local:Loc ButtonEarpieceC}"/>
<Button Click="ButtonRemoteC_Click"
x:Name="ButtonRemoteC"
Margin="5.5 14 8.5 0"
Style="{StaticResource ButtonSideMenu}"
Content="{local:Loc ButtonRemoteC}"/>
</StackPanel>
</Border>
</Grid>
</Window>
爲了記錄在案,我的按鈕的樣式資源:
<Style x:Key="ButtonSideMenu" TargetType="Button">
<Setter Property="TextBlock.TextAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Height" Value="92"/>
<Setter Property="Background" Value="{StaticResource ColorButtonBackground}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="{StaticResource ControlCornerRadius}" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="FontWeight" Value="DemiBold"/>
<Setter Property="Background" Value="{StaticResource ColorLayoutLine}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Background" Value="{StaticResource ColorBoldSelectedButton}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
而且我MainWindow.xaml.cs:
namespace XXXX.UserInterface
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonCovertC_Click(object sender, RoutedEventArgs e)
{
}
private void ButtonEarpieceC_Click(object sender, RoutedEventArgs e)
{
}
private void ButtonRemoteC_Click(object sender, RoutedEventArgs e)
{
}
}
}
這是完美的。我前往模型窗口狀態和一個ViewModel來控制所有這些。對你的解決方案有點矯枉過正。謝謝! – Dexluce