ContentPresenter Content does not shown Correctly in a ItemsRepeater
Hi, i am creating a StepBar Control, in Vertical Orientation, and Left or Right DisplayMode (for Header Text), but ContentPresenter Content does not shown correctly.
as you can see BasicInfo shown as BasicInf and UploadFile shown as UploadF.
and this a Left DisplayMode
i uploaded a repro/sample project.
my StepBarItem is a
public partial class StepBarItem : ContentControl
and ControlTemplate defined like this:
<StackPanel VerticalAlignment="Top"
FlowDirection="{TemplateBinding FlowDirection}"
Orientation="Horizontal"
Spacing="5">
<Border x:Name="PART_Border"
Height="40"
MinWidth="40"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="{ThemeResource ControlSolidFillColorDefaultBrush}"
BorderBrush="{ThemeResource StepBarItemInActiveBorderBrush}"
BorderThickness="2"
CornerRadius="90"
FlowDirection="LeftToRight">
<TextBlock x:Name="PART_Number"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
Style="{StaticResource BaseTextBlockStyle}"
Text="{Binding Index, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</Border>
<ContentPresenter x:Name="PART_Content"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorPrimaryBrush}" />
</StackPanel>
and my StepBar is a
public partial class StepBar : Control
which i am using a ItemsRepeater with following Layout:
itemsRepeater.Layout = new UniformGridLayout()
{
MaximumRowsOrColumns = GetItemsCount(),
ItemsStretch = Orientation == Orientation.Horizontal ? UniformGridLayoutItemsStretch.Fill : UniformGridLayoutItemsStretch.None,
ItemsJustification = UniformGridLayoutItemsJustification.SpaceBetween,
Orientation = this.Orientation
};
and this is my StepBar ControlTemplate:
<Grid Padding="{TemplateBinding Padding}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid.Resources>
<x:Double x:Key="ProgressBarMinHeight">4</x:Double>
<x:Double x:Key="ProgressBarTrackHeight">4</x:Double>
</Grid.Resources>
<ProgressBar x:Name="PART_ProgressBarBack"
Margin="0,20,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top" />
<Rectangle x:Name="PART_Rectangle"
Width="4"
Margin="28,10,28,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="{ThemeResource ProgressBarBackground}"
Visibility="Collapsed" />
<Rectangle x:Name="PART_RectangleFill"
Width="4"
Height="0"
Margin="28,10,28,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="{ThemeResource ProgressBarForeground}"
Visibility="Collapsed" />
<ItemsRepeater x:Name="PART_ItemsRepeater"
ItemsSource="{TemplateBinding Items}" />
</Grid>
why ContentPresenter does not shown correctly? it seems that we can show full content by set a Width="200" for ContentPresenter, but this is not a solution, because content can be anything and width can be anything i cant set a width 200 for all items because some of them may need less or greater width. i need a Auto Width. i dont know why it is not working?