wpf Expander
<Expander.Header>
<DockPanel >
<Label Name="gropname" Content="{Binding Name,Converter={StaticResource GroupConver}}" />
</DockPanel >
</Expander.Header>
怎么动态改变分组的名字 比如 我的好友[10/65]
当数据源发生变化的时候去执行转换希望变成 我的好友[11/65]
求大神指点!!!!!
[解决办法]
数据源改变的时候去修改Label绑定的Name的值不就可以了吗?
[解决办法]
你的数据源必须要有通知啊,实现了INotifyPropertyChanged的,才会通知系统属性改变了
[解决办法]
考虑到你的问题应该是涉及到公司信息,所以不方便透漏全部信息,那么我就猜测能完成你那个效果的做法吧:
<Grid>
<Expander x:Name="expander1" HorizontalAlignment="Left" Margin="49,48,0,0" VerticalAlignment="Top">
<Expander.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Tag.Name, ElementName=expander1}"/>
<TextBlock Text="["/>
<TextBlock Text="{Binding Tag.Current, ElementName=expander1}"/>
<TextBlock Text="/"/>
<TextBlock Text="{Binding Tag.All, ElementName=expander1}"/>
<TextBlock Text="]"/>
</StackPanel>
</DataTemplate>
</Expander.HeaderTemplate>
</Expander>
<Button Content="某一时刻在线人数改变" HorizontalAlignment="Left" Margin="167,55,0,0" VerticalAlignment="Top" Width="136" Click="Button_Click"/>
</Grid>
public partial class TestWindow : Window
{
public class ExpanderTest:INotifyPropertyChanged
{
private String name;
/// <summary>
/// 部门名称
/// </summary>
public String Name
{
get { return name; }
set { name = value; }
}
private Int32 all;
/// <summary>
/// 部门总人数
/// </summary>
public Int32 All
{
get { return all; }
set
{
all = value;
NotifyPropertyChanged("All");
}
}
private Int32 current;
/// <summary>
/// 部门当前在线人数
/// </summary>
public Int32 Current
{
get { return current; }
set
{
current = value;
NotifyPropertyChanged("Current");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName = "")
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public TestWindow()
{
InitializeComponent();
/* ExpanderTest是我假设你能知道部门的名称和部门的实际人数
* 通过对Expander控件的Tag属性赋值,界面的Expander的Header用模板来改变
* 模板中有3个TextBlock分别绑定ExpanderTest中的3个属性
*/
ExpanderTest test = new ExpanderTest { Name = "OOXX", All = 10, Current = 0 };
this.expander1.Tag = test;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//这里就模拟在某一时刻,有人登录什么的,就改变Current这个属性
ExpanderTest temp = this.expander1.Tag as ExpanderTest;
if (temp != null) {
temp.Current++;
}
}
}