no estoy seguro de lo que estoy haciendo mal aquí ...WPF interfaz de usuario no actualizados al cambio de propiedad
tengo una tabla hash personalizado que tiene un método que permite a alguien para eliminar un "partNumber" (un valor) desde la HashTable.
El método de eliminación es de la siguiente manera:
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));
}
}
}
estoy Encuadernación valores subyacentes de la tabla hash de la interfaz de usuario; sin embargo, la interfaz de usuario no se actualiza después de que se borre un valor. Me aseguré de que no hay problemas con la ortografía, etc ...
Este es el margen de beneficio que tengo para mi WPF UI:
<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>
Este es el código que estoy llamando para eliminar el elemento en el HashTable al hacer clic en el botón:
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;
}
¿Qué estoy haciendo mal?
Gracias,
-Frinny
No relacionado con su pregunta, pero ¿por qué está utilizando 'String.Compare()' en lugar de '=='? – svick
Porque esa es la manera en que estoy acostumbrado a hacer las cosas. Principalmente trabajo con VB.NET y he encontrado que esta es la mejor manera de comparar cadenas. – Frinavale