wpf-style

Finding the default style for a type in code behind

微笑、不失礼 提交于 2019-11-30 19:37:34
In WPF, you can create a Style that acts as the default for a control type in XAML: <Style TargetType="{x:Type local:MyControl}"> . . . </Style> Then, when WPF goes to display that control, it looks up that Style from the resources based on the its type. I want to do the equivalent of this in the code-behind of my program. How do I find that Style ? ZF. You can search for the style in the Application-level resources by using the control type as the key: Style defaultStyle = Application.Current.TryFindResource(typeof(MyControl)) as Style; object globalStyleDefinedByApp; Style globalStyle = new

Reset inherited WPF style?

余生长醉 提交于 2019-11-30 04:56:45
问题 In the App.xaml portion of my application I have a ResourceDictionary element that targets things like DataGridColumnHeader and DataGridCell and applies custom styling to them. These definitions are global (in that they don't use a x:key - they apply to all instances of the type). Is it possible to completely reset the style of these types to the 'base' Aero theme (or whatever theme is currently in use) for use in a subsection of my application? I've tried using <Style TargetType="{x:Type

Error: 'Cannot create unknown type '{clr-namespace:NameSpace.Properties}Settings'.'

有些话、适合烂在心里 提交于 2019-11-28 07:15:13
I define my settings and styles in a ResourceDictionary: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:properties="clr-namespace:Kavand.UI.Properties"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary> <properties:Settings x:Key="settings" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> <Style x:Key="PopupMenu_StackPanel"> <Setter Property="TextBlock.FontSize" Value="{Binding Source={StaticResource settings}, Path=Default.Font_Menu_Size}" /> <Setter Property=

WPF changing button background on click

六月ゝ 毕业季﹏ 提交于 2019-11-28 01:44:30
I have a set of buttons in a side panel. I want to change the background of the button that has been clicked. I have tried to do that using style.trigger and the only property I could think of is IsPressed , but that doesn't help that much since it changes the background for a second (till the button is pressed [duh]). This is the code I've tried: <Style.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="SlateGray" /> <Setter Property="Foreground" Value="White"></Setter> </Trigger> </Style.Triggers> Another way I could think of was creating individual