Answer the question
In order to leave comments, you need to log in
How to create a stylesheet in xaml?
Hello. I can't find info on google because I don't know what to look for.
How to make an analogue of html + css in xaml in terms of generalizations?
Well, for example, in css, I create a class, prescribe properties in it. I can set separate properties for each element in the class. For example, I take a div, put text, a text field and a button in it. I create a class in the style file, add a style to it for the text, for the text field and for the button. In the div I specify a class equal to the class in the style sheet and everything inside the div gets the properties specified in the style sheet.
But in Hamley, such a construction does not work. Here are the styles.
<Window.Resources>
<Style x:Key="OneLine">
<Setter Property="TextBox.MaxLines" Value="1"/>
<Setter Property="TextBox.HorizontalAlignment" Value="Stretch"/>
<Setter Property="TextBox.Width" Value="auto"/>
<Setter Property="TextBox.Margin" Value="0,0,0,10"/>
<Setter Property="TextBlock.Width" Value="auto"/>
<Setter Property="TextBlock.HorizontalAlignment" Value="Stretch"/>
<Setter Property="TextBlock.TextWrapping" Value="WrapWithOverflow"/>
<Setter Property="TextBlock.Margin" Value="0,0,0,0"/>
<Setter Property="Grid.Height" Value="auto"/>
<Setter Property="Grid.Width" Value="auto"/>
<Setter Property="Grid.HorizontalAlignment" Value="Stretch"/>
<Setter Property="Grid.VerticalAlignment" Value="Top"/>
<Setter Property="Label.Width" Value="auto"/>
<Setter Property="Label.Margin" Value="10,10,10,10"/>
</Style>
</Window.Resources>
<StackPanel HorizontalAlignment="Stretch" Height="auto" VerticalAlignment="Stretch" Width="auto" Style="{StaticResource OneLine}">
<Style BasedOn="{StaticResource OneLine}">
</Style>
<Label Content="Прокси сервер:" Name="Label1" Style="{StaticResource OneLine}"/>
Answer the question
In order to leave comments, you need to log in
create styles separately for each element, if there are any common properties - make a separate style and then override it.
<Style BasedOn="{StaticResource {x:Type CheckBox}}" TargetType="{x:Type CheckBox}">
<Setter Property="CheckBox.HorizontalContentAlignment" Value="Left" />
<Setter Property="CheckBox.VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="1" />
</Style>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question