根据这个问题(DataTemplateSelector for Uniform Grid binding?),我仍然没有让我的Buttons / Textblocks遵守视图模型中它们绑定到的行和列。我只会在知道行和列绑定正确的情况下发布XAML(例如,Live Visual Tree告诉我Row为1,Column为1,但在网格上显示为其他...)。
如果您需要更多代码,请告诉我。这是XAML的一小部分。
<Grid DockPanel.Dock="Left" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="800" Height="400">
<ItemsControl ItemsSource="{Binding ObjCompositeCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid DockPanel.Dock="Top" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Name="objGrid" Grid.Row="1"
Rows="{Binding RowCount}"
Columns="{Binding ColumnCount}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value="{Binding Row}"/>
<Setter Property="Grid.Column" Value="{Binding Column}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type engine:ObjA}">
<Button Content="{Binding Id}" />
</DataTemplate>
<DataTemplate DataType="{x:Type engine:GridLabeller}">
<TextBlock Text="{Binding HeaderName}"/>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
</Grid>
答案 0 :(得分:0)
WPF中的Grid.Row
并不关心附加的Grid.Column
和Grid
属性。您需要使用RowDefinitions
和ColumnsDefinitions
创建一个Grid
,才能将这些属性设置为有效。
您可以基于RowCount
和ColumnCount
源属性的值在视图中以编程方式创建public class convertjsontoxml {
public static void main(String[]... args) {
String json_value="{\"glossary\":{\"title\":\"example glossary\",\"GlossDiv\":{\"title\":\"S\",\"GlossList\":{\"GlossEntry\":{\"ID\":\"SGML\",\"SortAs
\":\"SGML\",\"GlossTerm\":\"Standard Generalized Markup Language\",\"Acronym\":\"SGML\",\"Abbrev\":\"ISO 8879:1986\",\"GlossDef\":{\"para\":\"A meta-markup language,
used to create markup languages such as DocBook.\",\"GlossSeeAlso\":[\"GML\",\"XML\"]},\"GlossSee\":\"markup\"}}}}}";
System.out.println(convertjsontoxml.convert_json(json_value));
}
String json_value="";
public String convert_json(String json_value) {
String xml="<Response>";
try {
JSONObject jsoObject = new JSONObject(json_value);
xml = xml + XML.toString(jsoObject);
} catch (Exception e) {
System.out.println(e);
}
xml = xml + "</Response>";
return xml;
}
}
。