单元格模板化 Devexpress:GridControl 中的数据绑定不起作用
Databinding within Cell templated Devexpress:GridControl not working
我尝试将 属性 对象 StrategySubscription 中的列表 属性 SubscribedSymbols 作为列表的一部分绑定到 Devexpress GridControl 中特定列的每个单元格中的组合框,但无法将数据绑定到工作。
自动列生成器工作并将值填充到网格中。所以,我确定数据存在。
我附上了 xaml 代码和数据对象以及当前输出的屏幕截图。
你能帮忙让数据绑定正常工作吗?我希望将 SubscribedSymbols 中的字符串集合填充到模板化列中每个单元格的组合框中。
P.S.: 前 3 个网格列和关联单元格绑定得很好,唯一的问题在于将数据绑定到最后一列的每个单元格中的组合框。
public class StrategySubscription
{
public Guid StrategyId { get; set; }
public string StrategyName { get; set; }
public int CapitalAllocation { get; set; }
public List<string> SubscribedSymbols { get; set; }
public StrategySubscription(string strategyName, Guid strategyId, int capitalAllocation, List<SymbolSubscription> symbolSubscriptions)
{
StrategyName = strategyName;
StrategyId = strategyId;
CapitalAllocation = capitalAllocation;
SubscribedSymbols = symbolSubscriptions.Select(x => x.Symbol.SymbolId).ToList();
//SubscribedSymbols = String.Join(", ", symbolSubscriptions.Select(x => x.Symbol.SymbolId).OrderBy(x=>x));
}
}
<dxg:GridControl x:Name="StrategyGrid" ItemsSource="{Binding StrategySubscriptions}" AutoGenerateColumns="None">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Strategy Id" Binding="{Binding StrategyId}"/>
<dxg:GridColumn Header="Strategy Name" Binding="{Binding StrategyName}"/>
<dxg:GridColumn Header="Strategy Capitalization" Binding="{Binding CapitalAllocation}"/>
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AllowEditing="False" AutoWidth="True" BestFitArea="All" AllowBestFit="True" ShowGroupPanel="True" ShowSearchPanelMode="Always" NavigationStyle="Row"/>
</dxg:GridControl.View>
</dxg:GridControl>
将 Data
添加到您的绑定:
...
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Data.SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...
如果您使用 DE 控件,更好的选择是使用 dxe:ComboBoxEdit
而不是 ComboBox
。
...
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit
ItemsSource="{Binding Data.SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...
我尝试将 属性 对象 StrategySubscription 中的列表 属性 SubscribedSymbols 作为列表的一部分绑定到 Devexpress GridControl 中特定列的每个单元格中的组合框,但无法将数据绑定到工作。
自动列生成器工作并将值填充到网格中。所以,我确定数据存在。
我附上了 xaml 代码和数据对象以及当前输出的屏幕截图。
你能帮忙让数据绑定正常工作吗?我希望将 SubscribedSymbols 中的字符串集合填充到模板化列中每个单元格的组合框中。
P.S.: 前 3 个网格列和关联单元格绑定得很好,唯一的问题在于将数据绑定到最后一列的每个单元格中的组合框。
public class StrategySubscription
{
public Guid StrategyId { get; set; }
public string StrategyName { get; set; }
public int CapitalAllocation { get; set; }
public List<string> SubscribedSymbols { get; set; }
public StrategySubscription(string strategyName, Guid strategyId, int capitalAllocation, List<SymbolSubscription> symbolSubscriptions)
{
StrategyName = strategyName;
StrategyId = strategyId;
CapitalAllocation = capitalAllocation;
SubscribedSymbols = symbolSubscriptions.Select(x => x.Symbol.SymbolId).ToList();
//SubscribedSymbols = String.Join(", ", symbolSubscriptions.Select(x => x.Symbol.SymbolId).OrderBy(x=>x));
}
}
<dxg:GridControl x:Name="StrategyGrid" ItemsSource="{Binding StrategySubscriptions}" AutoGenerateColumns="None">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Strategy Id" Binding="{Binding StrategyId}"/>
<dxg:GridColumn Header="Strategy Name" Binding="{Binding StrategyName}"/>
<dxg:GridColumn Header="Strategy Capitalization" Binding="{Binding CapitalAllocation}"/>
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AllowEditing="False" AutoWidth="True" BestFitArea="All" AllowBestFit="True" ShowGroupPanel="True" ShowSearchPanelMode="Always" NavigationStyle="Row"/>
</dxg:GridControl.View>
</dxg:GridControl>
将 Data
添加到您的绑定:
...
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Data.SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...
如果您使用 DE 控件,更好的选择是使用 dxe:ComboBoxEdit
而不是 ComboBox
。
...
<dxg:GridColumn Header="Symbol Subscription">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit
ItemsSource="{Binding Data.SubscribedSymbols}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
...