4

Resources/Shared.xaml のスタイル定義 (更新):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:Double x:Key="fullHeight" >26</system:Double>
<system:Double x:Key="halfHeight" >16</system:Double>
<Thickness x:Key="m">10</Thickness>
<Style TargetType="Button">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
    <Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="Label">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="TextBlock">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
</Style>
<Style TargetType="TextBox">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
    <Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="PasswordBox">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
    <Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="ListView">
    <Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
    <Setter Property="Margin" Value="{StaticResource m}"/>
    <Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="ComboBox">
    <Setter Property="Margin" Value="{StaticResource m}"/>
</Style>
</ResourceDictionary>

窓:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Resources/Shared.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

ユーザー制御:

<StackPanel Orientation="Horizontal">
  <Label Content="Text" Background="AliceBlue"/>
  <Label Content="{Binding DecimalValue, FallbackValue=50}" Background="Aquamarine"/>
</StackPanel>

モデル:

    private decimal _DecimalValue;
    public decimal DecimalValue
    {
        get { return _DecimalValue; }
        set
        {
            if (_DecimalValue != value)
            {
                _DecimalValue = value;
                NotifyOfPropertyChange();
            }
        }
    }

違いがあれば、Caliburn.Microを使用しています。

結果:

ここに画像の説明を入力

なんで?

更新:いくつかのスヌーピングの後、最初のラベルの内側の TextBlock のマージンは 0 で、値のソースはデフォルトであり、2 番目のラベルは 10 でスタイルであることが判明しました。

更新 2:この質問を読んだ後、定義されたTextBlockスタイルをinsideに適用すべきではないことがわかりました。つまり、何らかの形でバインディングの存在がそれを変えるようです。TextBlocksLabelsLabel

4

1 に答える 1