wpf-style

How to use the DisplayMemberPath in a ListView with an ItemContainerStyle?

只谈情不闲聊 提交于 2021-02-08 10:21:25
问题 Within a ListView control, how to use the DisplayMemberPath property when I want to change the ItemContainerStyle ? I used a ListView control in the ControlTemplate of my control and the DisplayMemberPath property is set via Binding from outside of control. <ListView ItemsSource="{TemplateBinding ItemsSource}" DisplayMemberPath="{TemplateBinding DisplayMemberPath}"> <ListView.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListView.ItemsPanel>

Change FontSize in App resource from code behind

☆樱花仙子☆ 提交于 2021-02-05 08:12:09
问题 For a WPF TextBox control, I set the FontSize using a XAML style in my app.xaml like this: <System:Double x:Key="FontSizeVal">12</System:Double> <Style TargetType="{x:Type TextBlock}"> <Setter Property="FontSize" Value="{DynamicResource FontSizeVal}"/> </Style> I want change FontSizeVal from Code Behind instead. I tried to use the below code, but it did not work (System.InvalidCastException: 'Specified cast is not valid.'): App.Current.Resources["FontSizeVal"] = 10; How can I set the

Selection does hide the DataGridCell

冷暖自知 提交于 2021-01-28 12:30:52
问题 I have a data grid: <DataGrid x:Name="grid1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" IsReadOnly="True" Loaded="grid1_Loaded" AutoGeneratingColumn="grid1_AutoGeneratingColumn" SelectionUnit="Cell" MouseMove="Grid1_MouseMove" LoadingRow="grid1_LoadingRow" MouseLeave="grid1_MouseLeave"> <DataGrid.Resources> <Style TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridCell}">

WPF converter for labels' content

谁都会走 提交于 2020-05-17 06:32:36
问题 I'm trying to override the output of a label, say it contained "Account" and a client wants account rendered as "Member" (so kind of think of this as a localisation converter?) My Question; is this possible with "hardcoded" content? or MUST i create a static file containing all label content (with iNotifiyStatic of course)? *for binding? xaml: <Label Style="{StaticResource LabelLeft}" Content="Account Name:"></Label> Resource File: Including all attempts made, from multiple sources heres the

Why is my WPF style for CornerRadius not being applied in Windows 7?

自古美人都是妖i 提交于 2020-02-06 08:45:11
问题 I created a simple WPF App while answering an SO question, my solution works on my Windows 10 machine, but when I run the app on my Windows 7 laptop the style isn't being applied. I believe this is something to do with Window's style setting over riding my style, how can I force it to use mine instead? I'm running the same .exe on both machines. <Window.Resources> <Style x:Key="CircleButton" TargetType="Button"> <Style.Resources> <Style TargetType="{x:Type Border}"> <Setter Property=

Why is my WPF style for CornerRadius not being applied in Windows 7?

不羁的心 提交于 2020-02-06 08:44:12
问题 I created a simple WPF App while answering an SO question, my solution works on my Windows 10 machine, but when I run the app on my Windows 7 laptop the style isn't being applied. I believe this is something to do with Window's style setting over riding my style, how can I force it to use mine instead? I'm running the same .exe on both machines. <Window.Resources> <Style x:Key="CircleButton" TargetType="Button"> <Style.Resources> <Style TargetType="{x:Type Border}"> <Setter Property=

C# WPF Textblock different font color per line

[亡魂溺海] 提交于 2020-01-13 20:39:23
问题 I am trying to make each line of text on a WPF textblock display in a different color. I have the following code which makes the entire block's font color purple because that's the last color it's set to. How can I make it so each potion is displayed in a different color? private void btnShowPotions_Click(object sender, RoutedEventArgs e) { tbPotionInfo.Foreground = Brushes.Green; tbPotionInfo.Text = smallPotion.Name + "(" + smallPotion.AffectValue + ")\r\n"; tbPotionInfo.Foreground = Brushes

WPF changing button background on click

◇◆丶佛笑我妖孽 提交于 2020-01-09 08:03:15
问题 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

WPF Button style won't apply to second button

孤街浪徒 提交于 2020-01-06 02:38:22
问题 I have two buttons that use a static common style: <Button x:Name="BtnCreate" Height="22" Width="150" Style="{StaticResource Style.Button.Trash}"/> <Button x:Name="aefae" Height="22" Width="150" Style="{StaticResource Style.Button.Trash}"/> The style is very basic: <Style TargetType="Button" x:Key="Style.Button.Trash" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="Content"> <Setter.Value> <StackPanel Orientation="Horizontal" > <Image Source="{StaticResource Image.Trash}" Width=

Auto size Button Style

拜拜、爱过 提交于 2020-01-05 06:38:46
问题 I have this Style : <!--Normal Button Style --> <Style TargetType="{x:Type Button}" x:Key="NormalButtonStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ButtonBase}"> <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Effect="{DynamicResource ShadowEffect}" > <Grid.ColumnDefinitions> <ColumnDefinition Width="16"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},