이것은 단순한 예입니다. 나는 "폴더 찾아보기"기능을 포함하는 usercontrol을 가지고 있으며, 텍스트 상자와 버튼을 사용한다. 버튼을 클릭하면 찾아보기 대화 상자가 열리고 본질적으로 텍스트 상자에 내용이 채워집니다. Caliburn Micro Message.attach는 datacontext의 변경을 고려하지 않습니다.
<UserControl x:Class="MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<!-- Folder -->
<TextBlock>Path</TextBlock>
<DockPanel LastChildFill="True" Grid.Column="1">
<Button DockPanel.Dock="Right" cal:Message.Attach="[Event Click] = [Action BrowseHotFolder()]" Content="..." HorizontalAlignment="Left" Width="25" Height="25" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="0,0,5,0"/>
<TextBox Text="{Binding HotFolderPath, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
</DockPanel>
</Grid>
나는 개체의 수를 포함하는 목록 상자가 있습니다. 선택한 개체는이 사용자 정의 컨트롤로 datacontext로 입력됩니다.
<Window>
...
<Listbox ItemsSource="{Binding Items, Mode=OneWay}" SelectedItem="{Binding SelectedItem}">
...
<view:MyUserControl DataContext="{Binding SelectedItem}" />
</Window>
이제 목록 상자에 두 개의 항목이 있고 내가 선택한 첫 번째 항목이 있다고 가정 해 보겠습니다. MyUserControl의 텍스트 상자에 "foo"를 채 웁니다. 그런 다음 두 번째 항목을 선택하고 "막대"를 채 웁니다. 데이터 바인딩 잘 작동하며 두 항목 모두 올바른 값이 설정되어 있습니다. 그런 다음 첫 번째 항목에서 찾아보기 단추를 클릭하고 폴더를 선택하면 첫 번째 항목의 텍스트 상자가 선택한 경로로 변경됩니다. 그러나 두 번째 항목을 선택하고 폴더를 탐색하면 첫 번째 항목의 텍스트 상자가 변경됩니다.
내 생각 엔 메시지 첨부 구문이 올바른 항목에서 찾기 작업을 호출하지 않는다고 생각합니다. datacontext (현재 선택한 항목)를 무시하고 첫 번째 항목 만 사용합니다.
어떻게해야합니까?