В моем приложении есть пользовательская сетка данных, которая, когда ее источник пуст, должна отображать сообщение «Нет результатов», а когда источник не пустой, она должна отображать данные источника, и сообщение не должно отображаться.
Мой пользовательский массив данных:
namespace GenericControls
{
[TemplatePart(Name = "EmptyDataGridTextBlock", Type = typeof(TextBlock))]
public class CustomDataGrid : DataGrid
{
private TextBlock _txtEmptyDataGrid = null;
public static readonly DependencyProperty IsEmptyDataGridProperty = DependencyProperty.Register("IsEmptyDataGrid", typeof(bool), typeof(CustomDataGrid), null);
public static readonly DependencyProperty EmptyDataGridTextProperty = DependencyProperty.Register("EmptyDataGridText", typeof(string), typeof(CustomDataGrid), null);
public CustomDataGrid()
{
IsEmptyDataGrid = true;
}
public bool IsEmptyDataGrid
{
get
{
return (bool)base.GetValue(IsEmptyDataGridProperty);
}
set
{
base.SetValue(IsEmptyDataGridProperty, value);
if(_txtEmptyDataGrid != null)
{
_txtEmptyDataGrid.Visibility = IsEmptyDataGrid ? Visibility.Visible : Visibility.Collapsed;
}
}
}
public string EmptyDataGridText
{
get
{
if (_txtEmptyDataGrid != null)
{
return _txtEmptyDataGrid.Text;
}
return (string)base.GetValue(EmptyDataGridTextProperty);
}
set
{
if (_txtEmptyDataGrid != null)
{
_txtEmptyDataGrid.Text = value;
}
base.SetValue(EmptyDataGridTextProperty, value);
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_txtEmptyDataGrid = GetTemplateChild("EmptyDataGridTextBlock") as TextBlock;
if (_txtEmptyDataGrid != null)
{
_txtEmptyDataGrid.Text = EmptyDataGridText;
_txtEmptyDataGrid.Visibility = IsEmptyDataGrid ? Visibility.Visible : Visibility.Collapsed;
}
}
}
}
Мой XAML выглядит следующим образом: my: CustomDataGrid Height = "180" Name = "dgChildren" SelectedItem = "{Binding SelectedChild, Mode = TwoWay} "ItemsSource =" {Binding Childrens} " IsEmptyDataGrid =" {Binding IsEmptyDataGrid} ">
В моей модели представления у меня есть свойство IsEmptyDataGrid:
public bool IsEmptyDataGrid
{
get
{
return _isEmptyDataGrid;
}
set
{
_isEmptyDataGrid = value;
RaisePropertyChanged("IsEmptyDataGrid");
}
}
Моя проблема заключается в том, что, хотя в моей модели представления используется RaisePropertyChanged("IsEmptyDataGrid")
, она не попадает внутрь свойства IsEmptyDataGrid
в пользовательской сетке данных, и пустое сообщение отображается вместе с данными в источнике.
Что я делаю не так?
Заранее спасибо, Круви