Rich edit box crashes for me if I try to set the fontsize to it.
C# code:
REB_Value.Document.SetText(TextSetOptions.None, "Company Name, \nStreet name with zip code. \n123-456-7890");
The XAML:
<StackPanel Orientation="Vertical">
<TextBlock Text="Lable for this Field:" Style="{StaticResource TextBlockStyle}"/>
<RichEditBox Name="REB_Value"
ContextMenuOpening="OnContextMenuOpening"
Style="{StaticResource MyStyle}"
SelectionChanged="OnSelectionChanged" >
</RichEditBox>
</StackPanel>
Style:
<Style x:Key="MyStyle" TargetType="RichEditBox">
...
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="14"/>
...
</Style>
The page renders/Loads if I remove the property <Setter Property="FontSize" Value="14"/> or If I put an /n at the end of my string
ie: "Company Name, \nStreet name with zip code. \n123-456-7890\n"
There are other RichEditBoxes which works fine,
eg:
SomeOtherREB.Document.SetText(TextSetOptions.None, "123456789");
I don't understand why this is happening?
Can you show the crash stack? I tried to create a repro but couldn't hit the issue. Let me know what I need to change to hit the crash:
https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/REBCrash
Related
I have a baseButtonStyle, which should apply to all Buttons and all derived types. It works well for all Buttons (excluding derived).
<Style x:Key="BaseButtonStyle" Selector="is Button" >
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{StaticResource SecondaryFontBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource BlueButtonNormalBorderBrush}"/>
<Setter Property="Background" Value="{StaticResource BlueButtonNormalBackgroundBrush}"/>
<Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Margin" Value="10"/>
</Style>
Now I have an AdditionalTextButton derived from Button.
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using System;
namespace VW7OrbMachineAvalonia1.Components.Controls
{
public class AdditionalTextButton : Button
{
Type IStyleable.StyleKey => typeof(AdditionalTextButton);
/// <summary>
/// Bottom left displayed Text
/// </summary>
public string BottomLeftText
{
get { return (string)GetValue(BottomLeftTextProperty); }
set { SetValue(BottomLeftTextProperty, value); }
}
public static readonly StyledProperty<String> BottomLeftTextProperty =
AvaloniaProperty.Register<AdditionalTextButton, String>("BottomLeftText");
}
}
My understanding of the style behavior of Avalonia is, that the BaseButtonStyle should apply to to AdditionalTextButton because of the is Button Selector. But this does not happen.
Beside that, I have another style which should apply to all AdditionaltextButtons. This also works fine.
<Style x:Key="additionalTextButtonStyle" Selector="is vwaui:Additionaltextbutton">
<Setter Property="FontSize" Value="22"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" TextWrapping="Wrap" Text="{TemplateBinding BottomLeftText}"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
How can I get the result, that the AdditionalTextButton is styled by the BaseButtonStyle AND by the AdditionalTextButtonStyle? Setters from AdditionalTextButtonStyle should overwrite setters from BaseButtonStyle.
The problem is that your is selector syntax is wrong. If you change it to be:
Selector=":is(Button)"
and
Selector=":is(vwaui|Additionaltextbutton)"
Then this should work as expected.
Avalonia doesn't have the concept of inheriting styles directly. The area that Avalonia diverges from WPF, UWP, etc the most is its styling system. Avalonia's styling system is more similar to CSS.
So to achieve this you can use classes.
for example say you declare in XAML 3 buttons:
<Button />
<Button Classes="buttonStyle1" />
<Button Classes="buttonStyle1 buttonStyle2" />
you can then add styles like:
<Style Selector="Button">
<Setter Property="FontSize" Value="12" />
</Style>
<Style Selector="Button.buttonStyle1">
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="Button.buttonStyle2">
<Setter Property="Foreground" Value="Red" />
</Style>
This way you can compose or inherit several styles at once.
You can also override the template in a style if you want to significantly change the look.
I have a user control with defined resources.
Here is some code for illustration.
<UserControl.Resources>
<SolidColorBrush x:Key="foregroundColor" Color="Red"/>
<Style x:Key="buttonFontIconStyle" TargetType="FontIcon">
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"></Setter>
<Setter Property="Foreground" Value="{Binding ???}"></Setter>
</Style>
<Style x:Key="menuItemLabelStyle" TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Foreground" Value="{Binding ???}"></Setter>
</Style>
</UserControl.Resources>
Now, I wish to use value defined in foreground color for buttonFontIconStyle, menuItemLabelStyle (and many others). Is it somehow possible to bind to value from resources in resources, or is there a way to specifiy color once (in xaml preferrably) and use it in multiple resources styles?
You can use the StaticResource :
<Style x:Key="buttonFontIconStyle" TargetType="FontIcon">
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"></Setter>
<Setter Property="Foreground" Value="{StaticResource foregroundColor}"></Setter>
</Style>
<Style x:Key="menuItemLabelStyle" TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Foreground" Value="{StaticResource foregroundColor}"></Setter>
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border Name="Border" CornerRadius="6" Padding="2" BorderBrush="Black" BorderThickness="2,1">
<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
</Border>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The code above is currently what I have for my text box. What do I put in the ControlTemplate.Trigger in order for my border to change from its color black to Blue or increase the Border size when it is clicked on. I have tried a few things without any luck. This includes style.Triggers and events. Please post the code that goes between the ControlTemplate.Trigger.
This assumes you want to border to be changed when you have it focused, since clicking a textbox focuses it. There is no OnClick property available, this changes the border of a textbox once you have it focused.
<Trigger Property="IsKeyboardFocusWithin"
Value="True">
<Setter Property="BorderBrush"
TargetName="Border"
Value="Blue"/>
</Trigger>
Edit:
To simply remove focus, add the following MouseDown event handler to your Window or Page:
MouseDown="Window_MouseDown"
And in your code behind:
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
Keyboard.ClearFocus();
}
This will correctly remove focus from your TextBox and thus unset the trigger to have a black bar again.
Is it possible to set Foreground property from the Style? Looking like it has no effect.
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
It's simple be sure you bind it to a static resource
<Grid.Resources>
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
</Grid.Resources>
<TextBlock Style="{StaticResource MyPageNameStyle}" Text="WP8 Demodccxzcxzczsczczxcxzczczczcz" Margin="9,-7,0,0" />
Youll be able to see the effect in the xaml designer only
Here is the style from the Styles.xaml.
<Style x:Key="PageScrollViewerStyle" TargetType="ScrollViewer">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0,1,0,1"/>
<Setter Property="Margin" Value="-58,-15,-58,-15"/>
<Setter Property="Padding" Value="58,0,58,0"/>
<Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
</Style>
Regardless of the size of the browser window, nor if I set the values to "Visible" I am not presented with a scroll bar. Any suggestions on how to correct this?
I was fiddling with this and decided to try changing the order of the LayoutRoot Grid and the ScrollViewer and this seems to have fixed it.
I changed
<Grid x:Name="LayoutRoot" DataContext="{StaticResource ViewModel}">
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
...
</ScrollViewer>
</Grid>
to this:
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
<Grid x:Name="LayoutRoot" DataContext="{StaticResource ViewModel}">
...
</Grid>
</ScrollViewer>