This is a migrated thread and some comments may be shown as answers.

ContextMenu with RadComboBox Binding problems

1 Answer 70 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Benedikt asked on 03 Dec 2019, 02:23 PM

Hey together,

 

I have a MapControl in my application in which I have different MapLayers with different MapItemsControls.
To a few of them I want to add ContextMenues if someone rightclicks. For example to create a route from Pushpin A to B, to add it to some existing things etc.
To make the second option easy, I want to add a RadCombobox to the ContextMenue and populate it with the data of an ObservableCollection that is part of the DataContext of the RadWindow. 

The problem is, that the RadComboBox stays empty. If I add the RadComboBox directly without the ContextMenu it gets populated as it should.
Also if I put the ContextMenu directly into the MapLayer it populates, but I need the Source of the Pushpin as a Commandparameter later so I can trigger some things with the underlying element.

<map:MapLayer
    x:Name="MapLayerAufträge"
    >
    <map:MapItemsControl
        ItemsSource="{Binding AufträgeLocations}"
        >
        <map:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <map:Pushpin
                    Location="{Binding Location}"
                    Visibility="{Binding Path=IsVisible, Converter={StaticResource VisibleIfTrueConverter}}"
                    ToolTip="{Binding Name}"
                    MouseLeftButtonDown="MontageAufträgePushpin_MouseDown"
                    >
                    <map:Pushpin.Background>
                        <SolidColorBrush
                            Color="{Binding MontageEinteilung, Converter={StaticResource AuftragMontageEingeteiltPinFarbeConverter}}"
                            Opacity="0.8"
                            />
                    </map:Pushpin.Background>
                    <telerik:RadContextMenu.ContextMenu>
                        <telerik:RadContextMenu
                            x:Name="rcmKarte"
                            >
                            <telerik:RadMenuItem Header="Tour starten"/>
                            <telerik:RadMenuItem
                                Header="Zu Tour hinzufügen"
                                >
                                <telerik:RadComboBox
                                    ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadWindow}}, Path=DataContext.Touren, Mode=OneWay}"
                                    SelectedValuePath="ID"
                                    >
                                    <telerik:RadComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid
                                Margin="0 3"
                                >
                                                <StackPanel
                                    Orientation="Horizontal"
                                    >
                                                    <TextBlock Text="{Binding Monteure}"/>
                                                    <TextBlock Text=" KW: " />
                                                    <TextBlock Text="{Binding KWsString}"/>
                                                    <TextBlock Text=" (" />
                                                    <TextBlock Text="{Binding DatumStart, StringFormat=d}" />
                                                    <TextBlock Text="-" />
                                                    <TextBlock Text="{Binding DatumEnde, StringFormat=d}" />
                                                    <TextBlock Text=")" />
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </telerik:RadComboBox.ItemTemplate>
                                </telerik:RadComboBox>
                                <Button
                    Content="Bestätigen"
                    Command="{Binding PutInTourCommand}"
                    />
                            </telerik:RadMenuItem>
                        </telerik:RadContextMenu>
                    </telerik:RadContextMenu.ContextMenu>
 
                </map:Pushpin>
            </DataTemplate>
        </map:MapItemsControl.ItemTemplate>
    </map:MapItemsControl>
    <map:MapItemsControl
        ItemsSource="{Binding SelectedAufträgeLocations}"
        >
        <map:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <map:Pushpin
                    Location="{Binding LagerLocation.Location}"
                    ToolTip="{Binding Name}"
                    Template="{StaticResource LagerPushpinTemplate}"
                    PositionOrigin="0.45, 0.45"
                    >
                    <map:Pushpin.Background>
                        <SolidColorBrush
                            Color="#EF6C00"
                            />
                    </map:Pushpin.Background>
                </map:Pushpin>
            </DataTemplate>
        </map:MapItemsControl.ItemTemplate>
    </map:MapItemsControl>
    <map:MapItemsControl
        ItemsSource="{Binding SelectedAufträgeLocations}"
        >
        <map:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <map:Pushpin
                    Location="{Binding Location}"
                    ToolTip="{Binding Name}"
                    >
                    <map:Pushpin.Background>
                        <SolidColorBrush
                            Color="#EF6C00"
                            Opacity="0.8"
                            />
                    </map:Pushpin.Background>
                </map:Pushpin>
            </DataTemplate>
        </map:MapItemsControl.ItemTemplate>
    </map:MapItemsControl>
</map:MapLayer>

 

Has anyone an idea how I can achieve this?

 

Greetings,

Benedikt

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 06 Dec 2019, 12:38 PM

Hello Benedikt,

Thank you for the provided stacktrace.

I noticed that the RadComboBox in the RadContextMenu is bound with a RelativeSource Binding to its parent RadWindow. Note, that the RadContextMenu is shown inside a Popup, which is in a separate visual tree and I am assuming that the Binding does not work correctly, since the RadComboBox does not have such a parent when inside a Popup. 

What I can suggest is setting the DataContext of the RadContextMenu explicitly and utilizing its InheritDataContext property. You can check out the following thread where this scenario was discussed: DataContext binding ignored.

I hope you find this helpful. 

Regards,
Vladimir Stoyanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ContextMenu
Asked by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or