2011-12-19 6 views
0

私はWPFの初心者ですので、これはおそらく非常に簡単です。ボタンのクリック結果をカラムテンプレート(Caliburn Micro)のテキストボックスに入れる方法

次のアプリケーションは、グリッド内のデータから任意のプロセスを起動することです。

私は現在について不明だ部分が自動有線イベントハンドラに渡されるインスタンスに変化をもたらす方法で、特にBrowse(Row row)以下のモデルで:

XAML:

<Window x:Class="LauncherApp.Views.ShellView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:cm="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <TextBlock x:Name="Title" /> 
     <DataGrid AutoGenerateColumns="False" Name="dataGrid1" ItemsSource="{Binding Source}"> 
      <DataGrid.Columns> 
       <DataGridTemplateColumn> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          <Button Content="Run" cm:Message.Attach="Run($dataContext)" /> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
       <DataGridTemplateColumn Header="Folder"> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          <WrapPanel> 
           <TextBox Text="{Binding Folder}" x:Name="Folder" /> 
           <Button Content="Browse" cm:Message.Attach="Browse($dataContext)" /> 
          </WrapPanel> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
       <DataGridTextColumn Binding="{Binding Command}" Header="Command"/> 
      </DataGrid.Columns> 
     </DataGrid> 
    </Grid> 
</Window> 

モデル:

namespace LauncherApp.ViewModels 
{ 
    using Caliburn.Micro; 
    using System.Collections.ObjectModel; 
    using System.Windows; 
    using System.Diagnostics; 

    public class ShellViewModel : PropertyChangedBase 
    { 
     private string title; 
     public string Title 
     { 
      get { return title; } 
      set 
      { 
       if (title != value) 
       { 
        title = value; 
        RaisePropertyChangedEventImmediately("Title"); 
       } 
      } 
     } 

     public ShellViewModel() 
     { 
      Title = "Hello Caliburn.Micro"; 
      Source = new ObservableCollection<Row>(
       new[] 
       { 
        new Row {}, 
        new Row {}, 
       } 
      ); 
     } 

     public void Run(Row row) 
     { 
      Process process = new Process(); 
      process.StartInfo.FileName = row.Folder + row.Executable; 
      process.StartInfo.Arguments = row.Arguments; 
      process.Start(); 
     } 

     public void Browse(Row row) 
     { 
      var dialog = new System.Windows.Forms.FolderBrowserDialog(); 
      System.Windows.Forms.DialogResult result = dialog.ShowDialog(); 
      string path = dialog.SelectedPath; 

      row.Folder = path; // <-- THIS CHANGE DOES NOT MAKE IT BACK TO THE UI 

     } 

     public ObservableCollection<Row> Source { get; set; } 
    } 

    public class Row 
    { 
     public string Folder { get; set; } 
     public string Executable { get; set; } 
     public string Arguments { get; set; } 
    } 
} 

UPDATE:ここで私はそれを動作させるために行われた変更(EisenbergEffeのおかげですCT)

行クラスがPropertyChangeBase

public class Row : PropertyChangedBase // <-- add 
{ 
    public string Folder { get; set; } 
    public string Executable { get; set; } 
    public string Arguments { get; set; } 
} 

変更通知を継承更新

public void Browse(Row row) 
    { 
     var dialog = new System.Windows.Forms.FolderBrowserDialog(); 
     System.Windows.Forms.DialogResult result = dialog.ShowDialog(); 
     string path = dialog.SelectedPath; 
     row.Folder = path; 
     row.RaisePropertyChangedEventImmediately("Folder"); // <-- add 
    } 

答えて

0

した後は、行の上にINotifyPropertyChangedのを実装する(またはCaliburn.MicroのPropertyChangeBaseから継承)と上げることを確認する必要がありますプロパティーセッターの適切なイベント

関連する問題