【发布时间】:2015-02-11 13:12:42
【问题描述】:
我在这个问题上被困太久了。我已经尝试了很多选项,但我无法让语法正确。我尝试过的所有选项都显示数据类型、所有元素的相同名称、空白工具提示、无工具提示或 LED 位值。我可以显示一个 LED 数组,其中颜色由位值确定,但我需要将每个元素的名称添加到工具提示中。我使用数据模板来显示数组。
我最近的 xaml:
<Window.Resources>
<DataTemplate x:Key="myLedTemplate" DataType="{x:Type sys:Byte}" >
<Border ... Background="{Binding Converter={StaticResource LEDConverter}}" ToolTip="{Binding Ledname}"/>
</DataTemplate>
<DataTemplate x:Key="myHwTemplate">
<Grid>
<Border>
<Grid>
<ItemsControl ItemsSource="{Binding Path=Led}" ItemTemplate="{StaticResource myLedTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ItemsControl.ItemsPanel>
...
</ItemsControl.ItemsPanel>
<ItemsControl.ToolTip>
<ToolTip>
<TextBlock Text="{Binding Path=Ledname}"/>
</ToolTip>
</ItemsControl.ToolTip>
</ItemsControl>
</Grid>
</Border>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl Name="hwItemControl" ItemTemplate="{StaticResource myHwTemplate}" ... >
...
</ItemsControl>
</Grid>
</Window>
我的班级类型
private byte[] led;
public byte[] Led
{
get { return led; }
set
{
byte[] input = value;
if (input != this.led)
{
this.led = input;
NotifyPropertyChanged();
}
}
}
private string[] ledname;
public string[] Ledname
{
get { return ledname; }
set
{
string[] input = value;
if (input != this.ledname)
{
this.ledname = input;
NotifyPropertyChanged();
}
}
}
就目前而言,如果我将鼠标悬停在 LED 元素上,它会显示“string[] Array”。感谢您提供的任何建议。
【问题讨论】:
-
因为 Ledname 是
string[]。你想展示什么?您想在工具提示中查看整个列表,还是每个 LED 都有一个对应的 LED 名称? -
第二个选项。每个 LED 一个名称。
标签: arrays wpf data-binding tooltip datatemplate