私はカスタムコントロールNumericUpDownを持っています。私はコントロールを拡張したい名前付きのスタイルを作成しました。この場合はグリッドにラップし、ラベルを追加します。ContentPresenterがスタイル内にカスタムコントロールを表示しない
ボタンを基本的な例として使用すると、ControlTemplateを拡張することができます。元のButtonはContentPresenterの位置に表示され、レイアウトのために他のコントロールを追加することができます。私のカスタムコントロールを使用している場合
ControlTemplate TargetType="{x:Type Button}">
<Border BorderThickness="3" BorderBrush="Red" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
しかし、のContentPresenterはNumericUpDownコントロールを表示しません、それは絶対に何も表示されません。最も基本的な形式でも、私はContentPresenterにカスタムコントロールを表示することはできません。
<Style x:Key="LabeledNumericUpDown2" TargetType="{x:Type controls:NumericUpDown}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:NumericUpDown}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Blabla"/>
<ContentPresenter Grid.Column="1"/>
<!--<controls:NumericUpDown Grid.Column="1"/>-->
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
私の人生のために私が欠けているものを理解することはできません。
ご協力いただきありがとうございます。
編集
NumericUpDownをカスタムコントロールもNumericUpDownコントロールを定義するデフォルトのスタイルを持っています。私はこれに名前付きのスタイルを拡張したいと思います。
<Style TargetType="{x:Type controls:NumericUpDown}">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Margin" Value="0" />
<Setter Property="Height" Value="18" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:NumericUpDown}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="16" />
</Grid.ColumnDefinitions>
<TextBox x:Name="PART_TextBox" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Padding="0" Margin="0"
Text="{Binding DisplayValue, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
<Border Grid.Column="1" BorderThickness="0 1 1 1" BorderBrush="#FFABADB3">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8" />
<RowDefinition Height="8" />
</Grid.RowDefinitions>
<Button x:Name="PART_ButtonUp" Grid.Row="0" Content="▲" FontSize="4" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" BorderThickness="0" Padding="6 1 0 0" />
<Button x:Name="PART_ButtonDown" Grid.Row="1" Content="▼" FontSize="4" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" BorderThickness="0" Padding="6 1 0 0" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ご迷惑をおかけして申し訳ございません。カスタムコントロールには既定のスタイルもあります。それを質問に追加します。 – JTK
私の答えを更新しました。 – toadflakz
クイックアンサーのための乾杯。あなたが言ったことを試しましたが、最も基本的なテストとパーツなしのデフォルトスタイルでも、ContentPresenterは何も表示しません。 – JTK