0

我有一个带有模板网格的 ItemControls,我在其中放置带有 colspan 的项目(按钮)(我正在实现一个日历)。当输入按钮的文本太大时,按钮宽度超过 colspan。这是隐藏超出文本的方法吗?

编辑

xml:

<ItemsControl Grid.Column="1" ItemsSource="{Binding Prenotazioni}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid>
                <Grid.Style>
                    <Style>
                        <Setter Property="Grid.Background">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource GridColumnsDefinitionsSetter}">
                                    <Binding RelativeSource="{RelativeSource Self}" />
                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="Periodo" />
                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
                                    <Binding Path="." />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Grid.Style>
            </Grid>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button 
                Command="{x:Static local:Timeline.SelectCommand}" 
                CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}}" 
                CommandParameter="{Binding .}">
                <Button.ToolTip>
                    <local:SchedaServizioPrenotato />
                </Button.ToolTip>
                <Button.Style>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Background" Value="LightYellow"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Prenotazione.Annullata}" Value="True">
                                <Setter Property="Background" Value="LightSalmon"/>
                                <Setter Property="Opacity" Value="0.4"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Prenotazione.Confermata}" Value="True">
                                <Setter Property="Background" Value="LightBlue"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
                <TextBlock Text="{Binding Prenotazione.Nominativo}" TextTrimming="WordEllipsis"/>
            </Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Grid.Column">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource ItemColumnSetter}">
                        <Binding RelativeSource="{RelativeSource Self}" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="Periodo" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
                        <Binding Path="Periodo.Inizio" />
                        <Binding Path="Periodo.Fine" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
            <Setter Property="Grid.Row">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource ItemRowSetter}">
                        <Binding RelativeSource="{RelativeSource Self}" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="Periodo" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
                        <Binding Path="." />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}" Path="DataContext" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
            <Setter Property="Grid.ColumnSpan">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource ItemColumnSpanSetter}">
                        <Binding RelativeSource="{RelativeSource Self}" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="Periodo" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
                        <Binding Path="." />
                        <Binding Path="Periodo.Inizio" />
                        <Binding Path="Periodo.Fine" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
            <Setter Property="FrameworkElement.Visibility">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource ItemVisibilitySetter}">
                        <Binding RelativeSource="{RelativeSource Self}" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="Periodo" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
                        <Binding Path="Periodo.Inizio" />
                        <Binding Path="Periodo.Fine" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

编辑

为清楚起见,我在 Grid.Background 转换器上设置了列定义

4

2 回答 2

0

还有一个叫做 ClipToBound 和 TextWrapping 的属性,看看这个

TextWrapping="Wrap"
于 2012-07-04T12:23:26.350 回答
0

你可以做这样的事情:

<Button>
    <TextBlock Text="Text" TextTrimming="WordEllipsis"/>
</Button>
于 2012-07-04T12:14:36.033 回答