1
如何更改wpf listview項目文本沒有listview1.Items[0].Refresh();
方法?如何更改wpf listview項目文本
我的XAML代碼:
<ListView Height="233" HorizontalAlignment="Left" Margin="0,78,0,0" Name="listView1" VerticalAlignment="Top" Width="503" IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn x:Name="GridViewColumnName1" Header="Files" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid Width="{Binding ActualWidth, ElementName=GridViewColumnName1}">
<StackPanel Orientation="Vertical" Grid.Column="1" Margin="8,0">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding ItemsName,Mode=TwoWay}" Name="listnameLB"></Label>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我的代碼:
private ListViewItemsData ListviewObject;
public class ListViewItemsData
{
public string ItemsName { get; set; }
}
private void button2_Click(object sender, RoutedEventArgs e)
{
listView1.Items.Add(new ListViewItemsData()
{
ItemsName = "ABCD"
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//ListviewObject = new ListViewItemsData();
ListviewObject = (ListViewItemsData)listView1.Items[0];
ListviewObject.ItemsName = "EFGH";
//listView1.Items.Refresh();
}
我要改變 「ItemsName」 標籤內容爲Button1事件。
Thaks!這項工作! :) – Gabee8