[英]Initializing a view in XAML with WPF (Caliburn.Micro)
我一直在尝试获取工具提示以在datagrid的每一行中工作。 我可以使用简单的StackPanel和一些标签在Tooltip
属性中显示信息,但是现在我想插入一个视图以用作工具提示。
我能够显示ciew,并且viewmodel在工作,但是我无法使自定义对象工作(名为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方法,但是随时建议另一种方法。 谢谢
您可以创建一个新视图并传递DataContext。 您可以在该视图中放入您喜欢的任何内容。 在您的主视图中看起来像这样。
<StackPanel>
<local:"YOUR_VIEW" DataContext="{Binding AppointmentConfirmation, Mode=TwoWay}"/>
</StackPanel>
您新创建的视图将如下所示。 您可以添加任何您喜欢的内容(只要它存在于您的DataContext中),并且可以将此视图重用于其他目的。
<UserControl x:Name="YOUR_VIEW" ....
...... >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0">
<Label>ID : </Label>
<Label Content="{Binding AppointmentID}"/>
</WrapPanel>
</Grid>
</UserControl>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.