其他分享
首页 > 其他分享> > itemsControl使用

itemsControl使用

作者:互联网

<StackPanel Width="800" >
  <ItemsControl ItemsSource="{Binding UserAccountDisply}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<UniformGrid Rows="1" Background="#87CEFF" Margin="2 0" HorizontalAlignment="Right" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" Style="{StaticResource DisplayMember}" ></TextBlock>
<TextBlock Text="{Binding Department}" Style="{StaticResource DisplayMember}"></TextBlock>
<TextBlock Text="{Binding Account}" Style="{StaticResource DisplayMember}"></TextBlock>
<TextBlock Text="{Binding Priority}" Style="{StaticResource DisplayMember}"></TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Width="160">
<Button Content="&#xe60f;" FontFamily="../Resources/fonts/#iconfont" FontSize="22" MinWidth="50"></Button>
<Button Content="&#xe7b0;" FontFamily="../Resources/fonts/#iconfont" FontSize="22" MinWidth="50"></Button>
</StackPanel>
</UniformGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>

 

viewmodel里写法

class UserAccountViewModel
{
public ObservableCollection<UserAccount> UserAccountDisply { get; set; }
public UserAccountViewModel()
{
this.UserAccountDisply = new ObservableCollection<UserAccount>();
this.UserAccountDisply.Add(new UserAccount("超级管理员", "西南交大", "root", "管理员"));
this.UserAccountDisply.Add(new UserAccount("操作员", "检修车间", "123", "操作员"));
}
}

model里

public class UserAccount
{
public string Name { get; set; }
public string Department { get; set; }
public string Account { get; set; }
public string Priority { get; set; }
public UserAccount( string name,string department,string account,string priority)
{
this.Name = name;
this.Department = department;
this.Account = account;
this.Priority = priority;
}
}

标签:set,string,get,UserAccountDisply,itemsControl,使用,UserAccount,public
来源: https://www.cnblogs.com/MyWPF/p/14263026.html