나는 Listbox와 몇 개의 버튼이 포함 된 UserControl을 가지고 있습니다. UserControl과 목록 상자 및 부모 컨트롤 (MVVM) 간의 바인딩
<UserControl x:Class="ItemControls.ListBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Grid>
<ListBox:ExtendedListBox SelectionMode="Single" ItemsSource="{Binding LBItems}" Height="184">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Command="RemoveCommand"/>
</Grid>
</UserControl>
그리고 뒤에있는 코드 :
public static readonly DependencyProperty RemoveCommandProperty =
DependencyProperty.Register("RemoveCommand", typeof(ICommand), typeof(ListBoxControl), null);
public ICommand RemoveCommand
{
get { return (ICommand)GetValue(RemoveCommandProperty); }
set { SetValue(RemoveCommandProperty, value); }
}
public static readonly DependencyProperty LBItemsProperty =
DependencyProperty.Register("LBItems", typeof(IEnumerable), typeof(ListBoxControl), null);
public IEnumerable LBItems
{
get { return (IEnumerable)GetValue(LBItemsProperty); }
set { SetValue(LBItemsProperty, value); }
}
나는이 같은 관점에서이 컨트롤을 사용하고 있습니다 : 목록 상자 바인딩하지만이 명령은 잘 작동
<ItemControls:ListBoxControl Height="240" Width="350" LBItems="{Binding Items, Converter={StaticResource ItemsConverter}, Mode=TwoWay}" RemoveCommand="{Binding RemoveCommand}"/>
는하지 않습니다 . 내 질문은 - 왜?
나는이 코드를 오늘 일찍 시도했지만 (this.DataContext = 초기화에서)이 제안을 시도했지만 여전히 운이 없다. – Walkor
나는 그 문제를 안다고 생각한다. 표시 할 내 답변을 수정했습니다. – Stephan
굉장! 많은 고마워요, 스테판 너는 내 하루를 보냈고, 나는 이것에 10 시간을 보냈다. – Walkor