2

私にはListBoxコントロールがあります。以下のコードを使用してToolTipfor eachを設定する方法を教えてください。ListBoxItem

<ListBox Name="FillSelections" 
         VerticalContentAlignment="Stretch"
         Margin="1, 3, 1, 3"
         IsEnabled="True" 
         Grid.Column="0" 
         Background="Transparent"
         HorizontalContentAlignment="Center"
         SelectedItem="{Binding SelectedColor}"
         SelectionMode="Single"
         Style="{StaticResource HorizontalListBoxStyle}"
         ItemsSource="{Binding FillColors}"
         ItemTemplate="{StaticResource ColorsItemTemplate}">
</ListBox>

<DataTemplate x:Key="ColorsItemTemplate">
    <Border Width="20" 
            Height="16"
            BorderBrush="Black"
            BorderThickness="1">
        <Border.Background>
            <SolidColorBrush Color="{Binding}" />
        </Border.Background>
        <Path Stroke="Red" 
              StrokeThickness="3"
              x:Name="abc"
              Visibility="Hidden">
            <Path.Data>
                <LineGeometry StartPoint="0,16" EndPoint="20,0"/>
            </Path.Data>
        </Path>
    </Border>
    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding}" Value="#00FFFFFF">
            <Setter TargetName="abc" Property="Visibility" Value="Visible"/>
        </DataTrigger>
    </DataTemplate.Triggers>
</DataTemplate>
4

2 に答える 2

5

このようなことを試してください

<ListBox Width="400" Margin="10" 
         ItemsSource="{Binding Source={StaticResource myTodoList}}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=TaskName}" 
                       ToolTipService.ToolTip="{Binding Path=TheTooltipText}"/>
        </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>

もちろん、ItemsSource バインディングは、バインディング ソースが何であれ、バインディング Path パーツは、実際に表示したいリスト内のオブジェクトのパブリック プロパティで構成されます。

于 2012-09-14T19:33:12.040 に答える
2

のスタイルを作成できますListBoxItem。したがって、次のようなものがあります。

<Window x:Class="WpfApplication3.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="ListBoxItem">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <ToolTip>
                        <TextBlock>Hello</TextBlock>
                    </ToolTip>
                </Setter.Value>
            </Setter>
        </Style>
   </Window.Resources>
    <Grid>
        <ListBox>
            <ListBoxItem>
                <TextBlock Text="Hello" />
            </ListBoxItem>
        </ListBox>
    </Grid>
</Window>
于 2012-09-14T19:36:15.220 に答える