[英]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.