2016年3月8日火曜日

Wpf細かい書式

毎回忘れる細かい書式

・.Resource内での宣言
<.Resource>
     <DataTemplate DataType="{x:Type [namespace]:[class]}" />
</.Resource>

・ListBoxへのBinding
要素が1つなら
 <ListBox ItemsSource="{Binding [List]}" DisplayMemberPath="[Listの要素]"/>

要素が複数かつ色々変えるなら
<ListBox ItemsSource="{Binding [List]}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding [要素1]}"/>
                <TextBlock Text="{Binding [要素2]}"/>         
            </StackPanel>
         </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

選択できなくて良いなら
<ItemsControl ItemsSource="{Binding [List]}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border Background="LightPink" CornerRadius="20">
                <TextBlock Margin="1">
                                <!--Run Text="要素1 : " FontSize="10"/-->
                                <Run Text="{Binding [要素1]}" FontSize="10"/>
                                <LineBreak/>
                                <Run Text="要素2 : "/>
                                <Run Text="{Binding [要素2]}"/>
                </TextBlock>
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

・PropertyChangedの通知
public event PropertyChangedEventHandler PropertyChanged;

 private void NotifyPropertyChanged(string info)
 {
     if (PropertyChanged != null)
     {
         PropertyChanged(this, new PropertyChangedEventArgs(info));
     }
 }

0 件のコメント:

コメントを投稿