【问题标题】:Tooltip of a List of checkboxes in silverlightSilverlight 中复选框列表的工具提示
【发布时间】:2016-08-25 19:13:36
【问题描述】:

当鼠标悬停在图像上时,我想在 Silverlight 的工具提示中显示复选框列表。 数据是字符串属性的列表。 问题:复选框文本内容消失,只出现复选框。 如何同时显示框及其文本内容?谢谢。

Tooltip display

<ToolTipService.ToolTip >
            <ToolTip d:DataContext="{d:DesignInstance Type=local:Data}">
                    <ListBox x:Name="LstTemp">

                    <!--<ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalAlignment" Value="{Binding Input}"/>
                        </Style>
                    </ListBox.ItemContainerStyle>-->

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox  IsChecked="true" IsEnabled="False" Content="{Binding Input}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </ToolTip>
</ToolTipService.ToolTip>
    </Image>
</Grid>

背后的代码

Public Class Data
    Public Property Data1 As String
    Public Property Data2 As String
    Public Property Input As New List(Of String)
End Class

【问题讨论】:

  • 你真的可以与工具提示中的内容进行交互吗?我记得不是这样。另外,为什么在ListBox 中使用CheckBoxes? ListBox 是一个交互式容器,CheckBox 是一个交互式项目。 ItemsControl 本身会更好,这样容器就不会干扰项目。
  • 在 XAML 代码的注释部分中,我从字符串属性列表中获取项目及其文本,但不是复选框。使用复选框部分,我得到了复选框,但没有得到复选框的文本(内容),请参见照片。

标签: xaml silverlight data-binding listbox tooltip


【解决方案1】:

我找到了解决方案,这里是工具提示中复选框动态列表的代码

            <Image Height="114" HorizontalAlignment="Left" Margin="129,48,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="170" Source="/Tooltip1;component/Images/Desert.jpg" >

<ToolTipService.ToolTip >
            <ToolTip d:DataContext="{d:DesignInstance Type=local:Data}">
                <ListBox x:Name="LstTemp">
                    <ListBox.ItemContainerStyle>

                            <Style TargetType="ListBoxItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <Grid Margin="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <CheckBox IsChecked="true" IsEnabled="false"/>
                                                <ContentPresenter
                                Grid.Column="1"
                                Margin="2,0,0,0" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                    </ListBox.ItemContainerStyle>
                </ListBox>
            </ToolTip>
</ToolTipService.ToolTip>
    </Image>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多