Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Want to access command from view model to RoomGroupUser Control
Used Proxy as Static resource at app.xaml
<Application.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<model:BindingProxy x:Key="proxy"/>
</Application.Resources>
Viewmodel has command I want to bind on Button
public ICommand cmdExpand
{
get { return new DelegateCommand(Expand); }
}
Used viewmodel as Datacontext fro whole TabItem so I can access it for all child elements
<TabItem.DataContext>
<viewModel:RoomAndRoomGroupViewmodel/>
</TabItem.DataContext>
RoomGroupControl generated using listview.
<ListView Name="lstRoomGroupList" ItemsSource="{Binding roomGroupList,Mode=TwoWay}" SelectedItem="{Binding selectdeGroup,Mode=TwoWay}"
HorizontalAlignment="Left" VerticalAlignment="Top" Background="Transparent"
BorderBrush="LightGray" BorderThickness="0,0,0,0" ScrollViewer.VerticalScrollBarVisibility="Visible"
Margin="0,0,0,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" OverridesDefaultStyle="False">
<ListView.ItemTemplate>
<DataTemplate>
<UserConrols:RoomGroupControl Grid.Row="2"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In RoomGroupContrl used BindProxy as
<Button Grid.Row="1" Command="{Binding Data.cmdExpand,Source={StaticResource proxy}}" Margin="7,0,1,0" Width="12" Height="12" Background="Transparent" BorderThickness="0" VerticalAlignment="Top"></Button>
Here is code for BindingProxy Class
public class BindingProxy : Freezable
{
#region Overrides of Freezable
protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
#endregion
public object Data
{
get { return (object)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
}
@VijayChuhan

This comment has been minimized.

Copy link
Owner Author

VijayChuhan commented Feb 17, 2016

please refer upper code... I want to Bind command cmdExpand from viewmodel on Button in UserRoomGroupControl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.