모델과 바인딩하려는 명령 단추 목록이 있습니다 (입력 포함). 버튼의 텍스트 상자를 어딘가에 바인딩하고 싶습니다 (viewmodel 참조).TextBox.TextProperty를 모델에서 Binding 유형의 속성에 바인딩
다음 코드는 내가 시도한 것이며 실패한 것입니다. 모델에 바인딩을 설정 한 다음 컨트롤에 바인딩 할 수 있습니까?
다른 말로하면 나는 어리석은 방법을 시도하고 있습니까?
보기 :
<ToolBar Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0" ItemsSource="{Binding SelectedTab.Commands}" Height="34">
<ToolBar.Resources>
<DataTemplate DataType="{x:Type model:ZoekCommandButtons}">
<Button Command="{Binding Command}" ToolTip="{Binding Tooltip}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image, Converter={StaticResource ImageConv}}" Height="16" Width="16"></Image>
**<TextBox Width="100" Text="{Binding Text}">**
<TextBox.InputBindings>
<KeyBinding Gesture="Enter" Command="{Binding Command}"></KeyBinding>
</TextBox.InputBindings>
</TextBox>
</StackPanel>
</Button>
</DataTemplate>
</ToolBar.Resources>
</ToolBar>
모델 :
public class ZoekCommandButtons : BaseModel, ICommandItem
{
private string _header;
private string _image;
private bool _isEnabled;
private Visibility _isVisible;
private ICommand _command;
private string _tooltip;
private Binding _text;
public Binding Text
{
get { return _text; }
set { _text = value; OnPropertyChanged("Text"); }
}
(etc)
뷰 모델 :
Commands.Add(new ZoekCommandButtons()
{
Image = "search.png",
IsEnabled = true,
**Text = new Binding { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(UserControl), 1), Path = new PropertyPath("FilterText") },**
Command = FilterCommand,
Tooltip = "Zoeken",
Header = "Zoeken"
});
의견을 보내 주셔서 감사합니다. 나는 정말로 필요한 것을 성취 할 다른 방법을 찾았고 Binding을 사용하여 Binding하지 않았습니다. 그러나 멋진 방법을 찾았습니다. –