I'm just getting into this and I just can't figure out what I am doing wrong.
I have the following XAML (at least the relevant part) followed by the code in the Viewmodel to load it.
In the seachcommand function I make a db call and load the results into my observable collection of SearchResultBag.
The query runs fun and I get data. It just doesn't show in the grid. What is the magic sauce I am missing. This seems like it should be trivial.
If I get rid of the SearchResultsBag and ONLY return a string (for testing purposes) the string(s) get displayed in the grid. Why won't my SearchResultsBag display it's contents. I've been a good boy and defined the template columns. It's gotta be something simple but I just can't see what I am missing.
While I'm at it, can anyone point me to a good MVVM databound RadGridView example. The telerik demo app is WAAAAY to complicated for a newb like me to pick up the basics from. I'm sure if I can get this simple search thing working I can get the rest.
Thanks ... Ed
<Button x:Name="cmdSearch" Grid.Row="8" Grid.Column="1" Content="Search" HorizontalAlignment="Left" Command="{Binding SearchCommand }" Margin="0,5,0,5"/>
<telerik:RadGridView Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="3" x:Name="ssSearch"
Visibility="{Binding ShowResults, Converter={StaticResource bResultsVisibleConverter}}"
ItemsSource="{Binding SearchResults, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay }"
Height="200"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Request #" DataMemberBinding="{Binding CustomKey}"/>
<telerik:GridViewDataColumn Header="ClientName" DataMemberBinding="{Binding ClientName}"/>
<telerik:GridViewDataColumn Header="ClientId" DataMemberBinding="{Binding ClientId}"/>
<telerik:GridViewDataColumn Header="OpenedBy" DataMemberBinding="{Binding OpenedBy}"/>
<telerik:GridViewDataColumn Header="ProjectId" DataMemberBinding="{Binding ProjectId}"/>
<telerik:GridViewDataColumn Header="OpenedDate" DataMemberBinding="{Binding OpenedDate}"/>
<telerik:GridViewDataColumn Header="RequestedDate" DataMemberBinding="{Binding RequestedDate}"/>
<telerik:GridViewDataColumn Header="CloseDate" DataMemberBinding="{Binding CloseDate}"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
SearchCommand = new Prism.Commands.DelegateCommand(Search).ObservesProperty(() => SearchResults);
private ObservableCollection<SearchResultsBag> _searchResults;
public ObservableCollection<SearchResultsBag> SearchResults
{
get { return _searchResults; }
set { SetProperty(ref _searchResults, value); }
}
private void Search()
{
this.SearchResults = new ObservableCollection<SearchResultsBag>();
var q = from a in db.CALMS_Request
where a.Custom_Key == CustomKey
select new SearchResultsBag
{
CustomKey = a.Custom_Key,
ClientName = a.Client.ClientName,
ClientId = a.Client.ClientId.ToString(),
OpenedBy = "OpenedBy",
ProjectId = a.ProjectID,
OpenDate = a.DateCreated.ToString(),
RequestedDate = a.RequestedDate,
CloseDate = a.ClosedDate
};
if (string.IsNullOrWhiteSpace(CustomKey))
q = q.Where(a => a.CustomKey.ToLower() == CustomKey.ToLower());
foreach (SearchResultsBag item in q)
this.SearchResults.Add(item);
ShowResults = true;
}
public class SearchResultsBag
{
public string CustomKey;
public string ClientName;
public string ClientId;
public string OpenedBy;
public string ProjectId;
public string OpenDate;
public string RequestedDate;
public string CloseDate;
}