Hi,
I've got a strange behavior regarding bindings. When I try to bind a property of a tool, for example the ButtonTool.Caption to my ViewModel, the binding never happens. (There are no binding errors listed in the Output window in VS). However, a binding does occur if I create my ViewModel as a resource and reference it using key throught StaticResource. Is this a bug? Why does the binding never occur?So this piece of code "works";
<
UserControl x:Class="IGDialog.MainPage"xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:x=http://schemas.microsoft.com/winfx/2006/xamlxmlns:d=http://schemas.microsoft.com/expression/blend/2008xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006xmlns:ig=infragistics.com/Controlsmc:Ignorable="d"xmlns:local="clr-namespace:IGDialog"d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources> <local:DataItem x:Key="DataItemHolder"/></UserControl.Resources><Grid x:Name="LayoutRoot" Background="White"> <ig:XamWebRibbon> <ig:XamWebRibbon.Tabs> <ig:XamWebRibbonTabItem Header="Tab1"> <ig:XamWebRibbonGroup Caption="Group 1"> <ig:ButtonTool Caption="{Binding Path=MyCaption, Source={StaticResource DataItemHolder}}"> </ig:ButtonTool> </ig:XamWebRibbonGroup> </ig:XamWebRibbonTabItem> </ig:XamWebRibbon.Tabs> </ig:XamWebRibbon></Grid></UserControl>
And this piece of code DOES NOT work;
<UserControl x:Class="IGDialog.MainPage"xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:x=http://schemas.microsoft.com/winfx/2006/xamlxmlns:d=http://schemas.microsoft.com/expression/blend/2008xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006xmlns:ig=http://infragistics.com/Controlsmc:Ignorable="d"xmlns:local="clr-namespace:IGDialog"d:DesignHeight="300" d:DesignWidth="400"><Grid x:Name="LayoutRoot" Background="White"> <ig:XamWebRibbon> <ig:XamWebRibbon.Tabs> <ig:XamWebRibbonTabItem Header="Tab1"> <ig:XamWebRibbonGroup Caption="Group 1"> <ig:ButtonTool Caption="{Binding Path=MyCaption}"> </ig:ButtonTool> </ig:XamWebRibbonGroup> </ig:XamWebRibbonTabItem> </ig:XamWebRibbon.Tabs> </ig:XamWebRibbon></Grid></UserControl>
public
MainPage(){ InitializeComponent(); this.DataContext = new DataItem();}
Thanks!
So the reason the second example doesn't work is because the ButtonTool is not a FrameworkElement and therefore - it doesn't have DataContext. It's derived from DependencyObject and, since Silverlight 4, you can bind it's properties but you have to provide a valid Source.
Hope that helps,
Thanks, I noticed that ButtonTool does not have a DataContext, so I figured this should do the trick;Caption="{Binding Path=DataContext.MyCaption, ElementName=LayoutRoot}"
but that does not work either...? Any other suggestions?