模板化的silverlight按钮没有正确调整大小

时间:2011-03-31 11:35:30

标签: silverlight xaml button controltemplate

我想创建一个类似于Visual Studio-s开放文档条带的UI。主要的想法是,我有一个列表框,我填写了打开文档的缩略图。我已应用以下模板:

<DataTemplate x:Key="ListBoxItemTemplate">
    <Grid x:Name="grid" Height="23" d:DesignWidth="100">
        <Rectangle x:Name="background" Grid.ColumnSpan="3" 
            Stretch="Fill" Fill="{StaticResource LinearMain02}" Margin="0"/>
      <TextBlock Text="text" Margin="4,0,25,0" Foreground="{StaticResource SolidBaseBrush}"
            VerticalAlignment="Center"/>
        <Button x:Name="button" Style="{StaticResource CloseButtonStyle}" 
            Foreground="{StaticResource SolidStrongBrush}" BorderBrush="{x:Null}" 
            Margin="0,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Right" 
            Width="15" Height="15" BorderThickness="0" Opacity="0"/>
    </Grid>
</DataTemplate>


<Style x:Key="CloseButtonStyle" TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
        <Grid Width="{TemplateBinding Height}" Height="{TemplateBinding Height}">
            <Ellipse Stroke="{StaticResource SolidBaseBrush}" Opacity="0"/>
              </Grid>
          </ControlTemplate>
       </Setter.Value>
    </Setter>
</Style>

ListBox本身并不多看,但这里是:

<ListBox Grid.Row="1" x:Name="list_tabs"
    ItemsSource="{Binding Thumbnails}" 
    SelectedItem="{Binding SelectedThumbnail, Mode=TwoWay}" 
    ItemTemplate="{StaticResource TabListItemTemplate}" BorderBrush="{x:Null}" 
    Padding="0" BorderThickness="0" 
    Background="{StaticResource LinearStrong10}">
<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <toolkit:WrapPanel Orientation="Horizontal" ItemHeight="30"/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

似乎项目的内容有多长并不重要,它仍然是100px宽。我想改变,所以该项目将遵循其内容的宽度。我忘记了什么?

0 个答案:

没有答案