简体   繁体   中英

Initializing a view in XAML with WPF (Caliburn.Micro)

I've been trying to get a tooltip to work inside of each row of a datagrid. I was able to displaythe info inside the Tooltip property using a simple StackPanel and some labels, but now I wanted to insert a view to use as a tooltip.

I was able to display the ciew and the viewmodel is working, yet I cannot make the custom object to work(named AppointmentConfirmationNotification ). I am able to use the empty object 'ToolTipContent' yet I want to bind it to the Datagrid.

here is the code I'm cureently working on. Be aware that I left a comment on my working Stackpanel 'experiment'. Basically I assume somehow I have to inser a mere ´{Binding}´ somewhere... But not sure where.

<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>

I was trying to do this on the XAML in order to follow a more MVVM approach, but feel free to advice another approach. Thank you

You can just make a new view and pass the DataContext through. You could put whatever you like in that view. It would look like this in your main view.

<StackPanel>
   <local:"YOUR_VIEW" DataContext="{Binding AppointmentConfirmation, Mode=TwoWay}"/>
</StackPanel>

Your freshly made view will look like this. You can add whatever you like (as long as it exists in your DataContext) and maybe reuse this view for other purposes.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM