Listbox only populating not in design mode - Silverlight
It only shows data in VS2010, not when in run-time.
<ListBox Margin="5" x:Name="RemoveLookup" ItemsSource="{Binding Path=LocationObjectResults}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="60" Loaded="Grid_Loaded">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="12*"/>
<ColumnDefinition Width="12*"/>
<ColumnDefinition Width="12*"/>
<ColumnDefinition Width="12*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<Border x:Name="lblID" Grid.Column="0" Style="{StaticResource CustomDisplayBorder}">
<TextBlock Style="{StaticResource CustomDisplayText}" Text="{Binding Path=ID}" />
</Border>
<Border Name="lblLocation" Grid.Column="1" Style="{StaticResource CustomDisplayBorder}">
<TextBlock Text="{Binding Path=Location}" Style="{StaticResource CustomDisplayText}"/>
</Border>
<Border Name="lblItemNum" Grid.Column="2" Style="{StaticResource CustomDisplayBorder}">
<TextBlock Text="{Binding Path=ItemNum}" Style="{StaticResource CustomDisplayText}"/>
</Border>
<Border Name="lblQuantity" Grid.Column="3" Style="{StaticResource CustomDisplayBorder}">
开发者_JAVA百科 <TextBlock Text="{Binding Path=LotCode}" Style="{StaticResource CustomDisplayText}"/>
</Border>
<Border Name="lblLotCode" Grid.Column="4" Style="{StaticResource CustomDisplayBorder}">
<TextBlock Text="{Binding Path=Quantity}" Style="{StaticResource CustomDisplayText}"/>
</Border>
<Border Name="lblFillDate" Grid.Column="5" Style="{StaticResource CustomDisplayBorder}">
<TextBlock Text="{Binding Path=FillDate}" Style="{StaticResource CustomDisplayText}"/>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ViewModel -
public RemoveViewModel()
{
if (!IsInDesignMode)
{
}
else
{
_locationObjectResults.Add(new LocationObject()
{
ID = "test",
Location = "test2",
ItemNum = "123123",
LotCode = "123123123",
Quantity = "500",
FillDate = DateTime.Now
});
}
}
public ObservableCollection<LocationObject> LocationObjectResults
{
get
{
return this._locationObjectResults;
}
set
{
this._locationObjectResults = value;
base.RaisePropertyChanged(() => this.LocationObjectResults);
}
}
public void PopulateLocationObjects()
{
//var itemList = new ObservableCollection<LocationObject>()
// {
// new LocationObject("test1","test2","test3","500","123123",DateTime.Now)
// };
_locationObjectResults.Add(new LocationObject()
{ ID = "test",
Location = "test2",
ItemNum = "123123",
LotCode = "123123123",
Quantity = "500",
FillDate = DateTime.Now
});
base.RaisePropertyChanged(() => this.LocationObjectResults);
}
The ViewModel is looking at a class called LocationObject that has ID, Location, etc... in it with standard Get;Set;'s
I see the data from my !IsInDesignMode test where I populate it but when clicking the cmdSubmit button it does not update in the UI even though I see RaisePropertyChanged() firing.
Any ideas?
EDIT :
Adding code for ViewModelBase -
private static bool? isInDesignMode;
public bool IsInDesignMode
{
get
{
if (!isInDesignMode.HasValue)
{
isInDesignMode = DesignerProperties.IsInDesignTool;
}
return isInDesignMode.Value;
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
{
if (propertyExpression.Body.NodeType == ExpressionType.MemberAccess)
{
var memberExpr = propertyExpression.Body as MemberExpression;
string propertyName = memberExpr.Member.Name;
this.OnPropertyChanged(propertyName);
}
}
This is the code from the parent grid
<UserControl.Resources>
<viewModels:RemoveViewModel x:Key="ViewModel" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded" DataContext="{Binding Source={StaticResource ViewModel}}">
How and where are you setting your DataContext
?
Try setting the BindingMode
to TwoWay
<ListBox Margin="5" x:Name="RemoveLookup" ItemsSource="{Binding Path=LocationObjectResults Mode=TwoWay}">
精彩评论