Created
May 23, 2013 07:13
-
-
Save dkalamari/5633231 to your computer and use it in GitHub Desktop.
WPF bind item command to parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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