2014-09-18 3 views
0

Visual Studio 2013 XAML 편집기에 더미 데이터가 표시되지 않습니다. makeDummy = true을 설정하고 실행하면 corrent 데이터 (올바른 레이블이있는 두 개의 필드)가 표시됩니다. 그러나 그것은 디자이너에 표시되지 않습니다. 디자인 모드에서 더미 데이터를 보는 방법은?디자인 타임 데이터가 표시되지 않습니까?

public partial class InputDialog : Window { 
    public ObservableCollection<KeyValueViewModel> Items { get; set; } 

    public InputDialog(){ 
     bool makeDummy = DesignerProperties.GetIsInDesignMode(this); 
     if (makeDummy) { 
      Items = new ObservableCollection<KeyValueViewModel>()    { 
       new KeyValueViewModel() {Key = "Top:"}, 
       new KeyValueViewModel() {Key = "Middleton:"} 
      }; 
     } 
     InitializeComponent(); 
    } 

    private void CancelButton_Click(object sender, RoutedEventArgs e) { DialogResult = false; } 
    private void OkButton_Click(object sender, RoutedEventArgs e) { DialogResult = true; } 
} 

속성, 인터페이스 상속, 이벤트 및 방법을 무시하십시오 - 그들은 단지 INotifyPropertyChanged에 필요한 동작을 구현 :이 XAML입니다

[NotifyPropertyChangedAspect] 
public class KeyValueViewModel : IRetrievableNotifyPropertyChanged{ 
    public string Value { get; set; } 
    public string Key { get; set; } 
    public event PropertyChangedEventHandler PropertyChanged; 
    public PropertyChangedEventHandler GetPropertyChangedEventHandler() { return PropertyChanged; } 
} 

:

<Window x:Class="Dre.InputDialog" 
     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" 
     mc:Ignorable="d" 
     DataContext="{Binding RelativeSource={RelativeSource Self}}" 
     d:DataContext="{Binding RelativeSource={RelativeSource Self}}" 
     FocusManager.FocusedElement="{Binding ElementName=FieldsContainerGrid}" 
     Height="165" Width="341">  
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="127*"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <Grid Name="FieldsContainerGrid" Margin="20,20,20,0" Grid.Row="0" MinWidth="100" MinHeight="50"> 
      <ListView ItemsSource="{Binding Items}"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <WrapPanel> 
          <Label Content="{Binding Key}" Background="Red"></Label> 
          <TextBox Text="{Binding Value}"></TextBox> 
         </WrapPanel> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 
     </Grid> 

     <StackPanel Margin="5" Grid.Row="1" HorizontalAlignment="Center" Orientation="Horizontal"> 
      <Button Margin="5" Width="100" Height="20" Click="OkButton_Click" IsDefault="True"> 
       Save 
      </Button> 
      <Button Margin="5" Width="100" Height="20" Click="CancelButton_Click" IsCancel="True"> 
       Cancel 
      </Button> 
     </StackPanel> 
    </Grid> 
</Window> 

답변

2

디자이너가 코드 숨김 클래스가 아닌 기본 클래스 (Window)를 인스턴스화합니다.

가장 간단한 해결 방법은 다음

d:DataContext="{x:Static local:DummyModel.Instance}" 
+0

당신이 무엇을 의미합니까 쓰기 정적 더미 모델 속성을 확인하는 것입니다? 'Window'는 보여줄 것이 없으며,'InputDialog'은 디자이너가 만들지 않습니다. – Tar

+0

정확하게. – SLaks

+0

디자이너가 "순수한"'Window' 인스턴스를 생성합니다.이 인스턴스에서는'XAML' ('ListView','Button', 등 ...)? 그럼'DesignerProperties.GetIsInDesignMode (this)'의 사용은 무엇입니까? – Tar