Skip to content

Instantly share code, notes, and snippets.

@dkalamari
Created May 23, 2013 07:13
Show Gist options
  • Save dkalamari/5633231 to your computer and use it in GitHub Desktop.
Save dkalamari/5633231 to your computer and use it in GitHub Desktop.
WPF bind item command to parent
//WPF part
<ItemsControl ItemsSource="{Binding companyList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton Command="{Binding Path= DataContext.ChooseCompanyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding CompanyID}" GroupName="Company" Content="{Binding CompanyName}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
//ViewModel
public CompanyInfoList companyList { get; private set; }
public DelegateCommand<string> ChooseCompanyCommand { get; set; }
//Constructor
public ReportDokumentViewModel()
{
//...
ChooseCompanyCommand = new DelegateCommand<string>(SetCompany, o => true);
}
public void SetCompany(string parameter)
{
//... LOGIC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment