Hello,
I'm using the following code in a UserControl:
<syncfusion:RibbonButton
x:Name="RtbIncomplete"
Command="{Binding ShowIncompleteRallysCommand}"
IsToggle="True"
Label="{Binding NotCompletedRallys}"
SizeForm="Small"
SmallIcon="{iconPacks:MaterialImage Kind=ProgressQuestion}">
<syncfusion:SfBadge.Badge>
<syncfusion:SfBadge
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Content="{Binding NotCompletedRallys}"
Fill="Warning"
HorizontalAnchor="Inside"
Shape="Oval"
VerticalAnchor="Inside" />
</syncfusion:SfBadge.Badge>
</syncfusion:RibbonButton>
The Property NotCompletedRallys in the ButtunLabel is found, the same property in the Content of the Badge is not found, giving me an xaml-Error:
Schweregrad Anzahl Datenkontext Bindungspfad Ziel Zieltyp Beschreibung Datei Zeile Projekt
Fehler 1 ShellViewModel NotCompletedRallys SfBadge.Content Object Die Eigenschaft "NotCompletedRallys" wurde im Objekt vom Typ "ShellViewModel" nicht gefunden. D:\Visual Studio 2022\SyncfusionBeachScouter\UserControls\RallyListDesktopUserControl.xaml 57 SyncfusionBeachScouter
It tells me, that the object is not found in the ShellViewModel, but the Property "NotCompletedRallys" is in the DesktopScoutingViewModel, which is a page in the MainView hosted in the ShellWindow. So the same Property is found in a RibbonButton, but not in the SfBadge.
By the way: when I use the RibbonButton with the SfBadge in the Ribbon of the DesktopScoutingPage, it works.
I have tried most of the usual things: RelativeSource, ElementName, Setting the DataContext directly, nothing works. Help available?
best regards
Jörg
Hi Jorg Ahmann,
We have prepared a sample based on the details you provided. In this sample, we set the DataContext in the MainWindow.xaml.cs instead of the DesktopScoutingPage.xaml.cs.
When the DataContext is set in the DesktopScoutingPage.xaml.cs, the binding for the SfBadge.Content fails because the SfBadge is part of an AdornerLayer, which is rendered outside the visual tree of the DesktopScoutingPage. As a result, it does not inherit the DataContext set on the DesktopScoutingPage.
By moving the DataContext assignment to the MainWindow.xaml.cs, the DesktopScoutingPage and its elements, including the AdornerLayer and SfBadge, can correctly inherit and utilize the shared DataContext.
Please find the attached sample for your reference. Kindly review the sample and let us know if it meets your requirements or if further adjustments are needed.
Regards,
Sekar Sivalingam