【发布时间】:2017-11-14 15:06:52
【问题描述】:
我一直在尝试让工具提示在数据网格的每一行中工作。我可以使用简单的 StackPanel 和一些标签来显示 Tooltipproperty 中的信息,但现在我想插入一个视图以用作工具提示。
我能够显示 ciew 并且视图模型正在工作,但我无法使自定义对象工作(名为 AppointmentConfirmationNotification)。我可以使用空对象“ToolTipContent”,但我想将它绑定到 Datagrid。
这是我正在处理的代码。请注意,我在 Stackpanel 的“实验”中留下了评论。基本上我假设我必须以某种方式在某处插入一个“{Binding}”......但不确定在哪里。
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Resources>
<model:AppointmentConfirmationNotification x:Key="ToolTipContent">
</model:AppointmentConfirmationNotification>
</Style.Resources>
<Setter Property="ToolTip">
<Setter.Value >
<!--
OLD STACKPANEL WORKING SAMPLE
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0">
<Label>ID : </Label>
<Label Content="{Binding AppointmentConfirmation.AppointmentID}"/>
</WrapPanel>
</Grid>
</StackPanel>
-->
<v:APTooltipView>
<v:APTooltipView.DataContext>
<ObjectDataProvider ObjectType="{x:Type vm:APTooltipViewModel}">
<ObjectDataProvider.ConstructorParameters>
<StaticResource ResourceKey="ToolTipContent"/>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</v:APTooltipView.DataContext>
</v:APTooltipView>
</Setter.Value>
</Setter>
<Setter Property="TextElement.FontWeight" Value="{Binding Path=Read,Converter={StaticResource BooleanToFontweight}}"/>
</Style>
</DataGrid.RowStyle>
我试图在 XAML 上执行此操作,以便遵循更多的 MVVM 方法,但请随时建议另一种方法。谢谢
【问题讨论】: