Tôi không chắc mình đang làm gì sai ở đây ...Giao diện người dùng WPF không được cập nhật khi thay đổi thuộc tính
Tôi có một HashTable tùy chỉnh có phương pháp cho phép ai đó xóa "partNumber" (giá trị) từ HashTable.
Phương pháp xóa như sau:
class COSC202HashTable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
//....
private List<int> underlyingList;
//...
public List<int> HashList { get { return underlyingList; } }
public void Delete(int partNumber)
{
string theAlgoritnm = Algorithm;
if (String.Compare(theAlgoritnm, "Modulo Division") == 0 && String.Compare(Probe, "Linear Collision Resolution") == 0)
{
LinearModularDivision(partNumber, false);
}
if (String.Compare(theAlgoritnm, "Modulo Division") == 0 && String.Compare(Probe, "Key Offset Collision Resolution") == 0)
{
KeyOffsetModularDivision(partNumber, false);
}
if (String.Compare(theAlgoritnm, "Pseudorandom") == 0)
{
Pseudorandom(partNumber, false);
}
if (String.Compare(theAlgoritnm, "Rotation") == 0)
{
Rotation(partNumber, false);
}
NotifyPropertyChanged("HashList");
}
//.......
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
Tôi ràng buộc giá trị cơ bản của Hashtable để giao diện người dùng; tuy nhiên giao diện người dùng không được cập nhật sau khi giá trị bị xóa. Tôi chắc chắn rằng không có vấn đề với chính tả vv ...
Đây là đánh dấu tôi đã cho UI WPF của tôi:
<Window.Resources>
<COSC202:COSC202HashTable x:Name="TheHashTable" x:Key="TheHashTable" PropertyChanged="TheHashTable_PropertyChanged"></COSC202:COSC202HashTable>
</Window.Resources>
<ListView x:Name="HashResults" Height="32" Width="1200" Margin="10" HorizontalAlignment="Right"
DataContext="{Binding Source={StaticResource TheHashTable}}" ItemsSource="{Binding Path=HashList}" HorizontalContentAlignment="Left">
<ListView.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,2">
<GradientStop Color="#FF000000" Offset="0"></GradientStop>
<GradientStop Color="DarkBlue" Offset="1"></GradientStop>
</LinearGradientBrush>
</ListView.Background>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Path=.}" FontSize="11" Foreground="Azure" VerticalAlignment="Top" ></TextBlock>
<Label Content="|" VerticalAlignment="Top" FontSize="5"></Label>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Đây là mã mà tôi đang kêu gọi để xóa các mục trong HashTable khi nhấp vào nút:
private void DeleteItem_Click(object sender, RoutedEventArgs e)
{
Object item = HashResults.SelectedItem;
COSC202HashTable theHashTable = (COSC202HashTable)this.Resources["TheHashTable"];
if (theHashTable != null && item != null)
{
theHashTable.Delete((int)item);
}
HashResults.SelectedIndex = -1;
}
Tôi đang làm gì sai?
Cảm ơn,
-Frinny
Không liên quan đến câu hỏi của bạn, nhưng tại sao bạn sử dụng 'String.Compare()' thay vì '=='? – svick
Vì đó là cách tôi thường làm. Tôi chủ yếu làm việc với VB.NET và tôi đã tìm thấy đây là cách tốt nhất để so sánh các chuỗi. – Frinavale