我不确定它是否可能,但值得尝试问一下。那么 - 有可能以某种方式添加控件到资源字典吗?
例如,我的风格适用于我的应用程序中的每个窗口:
<Style x:Key="WindowStyle" TargetType="Window">
<Setter Property="WindowState" Value="Maximized" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Width" Value="{DynamicResource {x:Static SystemParameters.PrimaryScreenWidth}}" />
<Setter Property="Height" Value="{DynamicResource {x:Static SystemParameters.PrimaryScreenHeight}}" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/myApp;component/Pictures/gradientBackground.png" />
</Setter.Value>
</Setter>
<Setter Property="Icon" Value="/myApp;component/Pictures/logo_small.png" />
</Style>
正如您所看到的,每个窗口都已最大化并且没有边框等 - 它只是全屏窗口。我想要做的是在右上角添加一个简单的按钮,它将作为最小化。
有什么想法吗?
提前致谢!
答案 0 :(得分:0)
<Style x:Key="WindowStyle" TargetType="Window">
<Setter Property="WindowState" Value="Maximized" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Width" Value="{DynamicResource {x:Static SystemParameters.PrimaryScreenWidth}}" />
<Setter Property="Height" Value="{DynamicResource {x:Static SystemParameters.PrimaryScreenHeight}}" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/myApp;component/Pictures/gradientBackground.png" />
</Setter.Value>
</Setter>
<Setter Property="Icon" Value="/myApp;component/Pictures/logo_small.png" />
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Content="X" HorizontalAlignment="Right" Margin="2"></Button>
<ContentControl Grid.Row="1" Content="{TemplateBinding Content}"></ContentControl>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>