0

I can't simply set the x:Name attribute of the ComboBox because there are more than one. I also don't know how to get a specific ComboBox from code, to set/get the Text property. Here is a simplified version of my XAML file:

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- its Page because i'm using Kaxaml -->
  <Page.Resources>
    <XmlDataProvider x:Key="PropertyData" XPath="/properties">
                <x:XData>
                <!-- This is actually in an external xml file -->
                    <properties xmlns="">
                        <property name="some property">
                            <item value="5"  />
                            <item value="10"  />
                            <item value="15"  />
                            <item value="20"  />
                        </property>
                        <property name="other property">
                            <item value="5"  />
                            <item value="10"  />
                            <item value="15"  />
                            <item value="20"  />
                        </property>
                    </properties>
                </x:XData>
            </XmlDataProvider>
  </Page.Resources>
  <ListView  DataContext="{StaticResource PropertyData}" ItemsSource="{Binding XPath=property}">
    <ListView.View>
      <GridView>
        <GridViewColumn Header="Property" DisplayMemberBinding="{Binding XPath=@name}" />
        <GridViewColumn Header="Value">
          <GridViewColumn.CellTemplate>
            <DataTemplate>
              <ComboBox Width="100" ItemsSource="{Binding XPath=item}"  DisplayMemberPath="@value"></ComboBox>
            </DataTemplate>
          </GridViewColumn.CellTemplate>
        </GridViewColumn>
      </GridView>
    </ListView.View>
  </ListView>
</Page>

Ok, if you can solve this you get the genius label. Thanks in advance...

  • U can define a name for the combobox, however u are right to asume that u wont find them the regular way, since there are more than one. Therfore u need to us FindVisualChild like in this post https://stackoverflow.com/questions/25229503/findvisualchild-reference-issue – Dom Jun 04 '23 at 19:16
  • *"I also don't know how to get a specific ComboBox from code, to set/get the Text property."* - Do you want to select an item? You do this via the `ListView.SelectedItem` or `ListView.SelectedIndex` properties. For example to select the first item you set `ListView.SelectedIndex` to `0`: `` –  Jun 04 '23 at 19:17

0 Answers0