Can't apply a style to TextBox
Hello there. This code works in Blend, but doesn't in XamlToy/Noesis app.
How to fix it (textBox2)?
How to fix it (textBox2)?
Code: Select all
<UserControl 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" mc:Ignorable="d"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
d:DesignHeight="384" d:DesignWidth="285" Width="285" Height="384">
<UserControl.Resources>
<ResourceDictionary>
<Style x:Key="DarkInput" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#FF221E22"/>
<Setter Property="BorderBrush" Value="#FF5B5B5B"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="MaxLines" Value="1"/>
<Setter Property="Padding" Value="0"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<StackPanel>
<TextBox x:Name="textBox1" Text="{Binding ValueR}" Height="25" MaxLength="3" Background="#FF221E22" BorderBrush="#FF5B5B5B" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" MaxLines="1" Margin="0,0,0,10" Padding="0"/>
<TextBox x:Name="textBox2" Text="{Binding ValueR}" Height="25" MaxLength="3" Style="{StaticResource DarkInput}"/>
</StackPanel>
</Grid>
</UserControl>
- antdeceive
- Posts: 1
- Joined:
Re: Can't apply a style to TextBox
It looks like the issue might be related to the style being applied to textBox2.snake game Since you mentioned that the code works in Blend but not in XamlToy/Noesis app, there could be a compatibility issue with the way styles are handled or applied in those environments.
One potential solution could be to remove the Style attribute from textBox2 and manually apply the style in the Loaded event handler of the UserControl.
One potential solution could be to remove the Style attribute from textBox2 and manually apply the style in the Loaded event handler of the UserControl.
-
sfernandez
Site Admin
- Posts: 3014
- Joined:
Re: Can't apply a style to TextBox
Hi, if you apply a local style without a template to a TextBox, your style should specify the BasedOn to inherit the template from the theme styles.
But I suggest you provide your own template, because the default one can have over or focus states that don't match the rest of your application theme.
Code: Select all
<Style x:Key="DarkInput" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
Re: Can't apply a style to TextBox
I see. Thank you!Hi, if you apply a local style without a template to a TextBox, your style should specify the BasedOn to inherit the template from the theme styles.But I suggest you provide your own template, because the default one can have over or focus states that don't match the rest of your application theme.Code: Select all<Style x:Key="DarkInput" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
Who is online
Users browsing this forum: No registered users and 2 guests