相关疑难解决方法(0)

如何定位所有控件(WPF样式)

我可以指定适用于所有元素的样式吗?我试过了

<Style TargetType="Control">
    <Setter Property="Margin" Value="0,5" />
</Style>
Run Code Online (Sandbox Code Playgroud)

但它没有做任何事情

wpf user-interface styles

81
推荐指数
2
解决办法
3万
查看次数

将样式应用于WPF中的所有派生类

我想将样式应用于从Control派生的所有类.这可能与WPF有关吗?以下示例不起作用.我希望Label,TextBox和Button的保证金为4.

<Window x:Class="WeatherInfo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Wetterbericht" Height="300" Width="300">
    <Window.Resources>
        <Style TargetType="Control">
            <Setter Property="Margin" Value="4"/>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel Margin="4" HorizontalAlignment="Left">            
            <Label>Zipcode</Label>
            <TextBox Name="Zipcode"></TextBox>
            <Button>get weather info</Button>
        </StackPanel>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

wpf xaml styles

8
推荐指数
2
解决办法
6265
查看次数

标签 统计

styles ×2

wpf ×2

user-interface ×1

xaml ×1