Data Standard Combobox items: attribute selected by another Combobox

Data Standard Combobox items: attribute selected by another Combobox

Leon.VASSE
Advocate Advocate
772 Views
1 Reply
Message 1 of 2

Data Standard Combobox items: attribute selected by another Combobox

Leon.VASSE
Advocate
Advocate

Hello,

 

In VDS GUI, I  wish to display, in a combobox, the specific attribute of a collection of items (say the description of articles in the language specified by the User).

My purpose is similar to the below unsolved post:

bind xml to list values in combobox

 

A Combobox1 should be populated with items StandardTextInfo listed in an XML file. Each item is made of the following properties:
-StandardTextNumber (item number in the items collection)
-StandardTextDE (German translation of the item)
-StandardTextEN (English translation of the item)
-StandardTextFR (French translation of the item)

Here is the StandardText.XML file:

<?xml version="1.0" encoding="utf-8"?>
<StandardTextData xmlns="">
  <StandardTextInfo StandardTextNumber="10" DE="KATZE" EN="CAT" FR="CHAT"></StandardTextInfo>
  <StandardTextInfo StandardTextNumber="20" DE="HUND" EN="DOG" FR="CHIEN"></StandardTextInfo>
  <StandardTextInfo StandardTextNumber="30" DE="PFERD" EN="HORSE" FR="CHEVAL"></StandardTextInfo>
</StandardTextData>

Combobox2 should be populated with items LanguageInfo listed in an XML file. Each item is made of the property LanguageName (DE=Deutsch, EN=English, FR=Francais). Here is the Language.XML file:

<?xml version="1.0" encoding="utf-8"?>
<LanguageData xmlns="">
  <LanguageInfo LanguageName="DE"></LanguageInfo>
  <LanguageInfo LanguageName="EN"></LanguageInfo>
  <LanguageInfo LanguageName="FR"></LanguageInfo>
</LanguageData>

 

Here is the intended usage:

-The User selects from Combobox2 the language that the items will be displayed in into Combobox1.

-The values displayed in Combobox1 DisplayMemberPath must be bound to the items property corresponding to the value selected in Combobox2. Items name can thus be displayed in the language chosen by the User.

-Beside, a Combobox3 displays the property StandardTextNumber of the item selected in Combobox1. By using a Combobox (I talk about Combobox3) rather than a Label, the User has also the alternative to directly select the item property StandardTextNumber, which reversely updates the item displayed on Combobox1 (still in the language defined in ComboBox2).

 

Here is the definition of the 3 comboboxes into the XAML file:

    <?xml version="1.0" encoding="utf-8"?>
    <WPF:MainWindow>
        x:Name="FileWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:CreateObject.WPF;assembly=CreateObject"

    <Window.Resources>
        <XmlDataProvider>
            x:Key="Languages"
            Source="C:\Language.xml"
            XPath="/LanguageData"
        </XmlDataProvider>
        <XmlDataProvider
            x:Key="StandardTexts"
            Source="C:\StandardText.xml"
            XPath="/StandardTextData"
        </XmlDataProvider>
    </Window.Resources>

    <ComboBox>
        x:Name="Combobox1"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource StandardTexts}, XPath="StandardTextInfo"}"
        SelectedItem="{Binding SelectedItem, ElementName=ComboBox3, Mode=OneWay}"
        SelectedValue="{Binding SelectedValue, ElementName=ComboBox2, Mode=OneWay}"
        SelectedValuePath="@StandardTextNumber"
        DisplayMemberPath="{Binding SelectedValue, ElementName=ComboBox3, Mode=OneWay}"
    </ComboBox>

    <ComboBox>
        x:Name="Combobox2"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource Languages}, XPath="LanguageInfo"}"
        SelectedValue="{Binding Prop[LanguageName].value}"
        SelectedValuePath="@LanguageName"
        DisplayMemberPath="@LanguageName"
    </ComboBox>

    <ComboBox>
        x:Name="Combobox3"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource StandardTexts}, XPath="StandardTextInfo"}"
        SelectedItem="{Binding SelectedItem, ElementName=ComboBox1, Mode=OneWay}"
        SelectedValue="{Binding SelectedValue, ElementName=ComboBox2, Mode=OneWay}"
        SelectedValuePath="{Binding SelectedValue, ElementName=ComboBox1, Mode=OneWay}"
        DisplayMemberPath="@StandardTextNumber"
    </ComboBox>

    </WPF:MainWindow>

 

My questions:

1) Combobox1 SelectedValue & DisplayMemberPath, Combobox3 SelectedValue & SelectedValuePath: I probably miss the logic: how should be expressed the desired bindings?

2) In XML, what is the purpose of the prefix @ at forehead of bound properties?

3) I am pretty sure there is no really need for the source Language.XML: is it possible to populate Combobox2 directly from the languages identified within the source StandardText.XML, as suggested in the above-mentionned post?

4) For the moment, I intend to store my collection of articles (and their several translation) into an xml file: is it the most convenient approach? To avoid managing a xml file out of VAULT, I was thinking to store those data within a VAULT numbering scheme (defined with 1 single pre-defined list field), but the available columns in pre-list fields of VAULT numbering scheme are, by construction, limited to 2 (I could only store the item number and only 1 of the intended language translation).

5) In which situation should the IsEnabled property be set to CreateMode or EditMode?

 

Thank you in advance for the kind advices you may provide.

Best regards

0 Likes
Accepted solutions (1)
773 Views
1 Reply
Reply (1)
Message 2 of 2

Leon.VASSE
Advocate
Advocate
Accepted solution

Hello,

 

Answer to question 1:

StandardText.XML and Language.XML files are not modified (see description in the above post)

Modification of the 3 comboboxes into File.XAML or Inventor.XAML files:

    <?xml version="1.0" encoding="utf-8"?>
    <WPF:MainWindow>
        x:Name="FileWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:CreateObject.WPF;assembly=CreateObject"

    <Window.Resources>
        <XmlDataProvider>
            x:Key="Languages"
            Source="C:\Language.xml"
            XPath="/LanguageData"
        </XmlDataProvider>
        <XmlDataProvider
            x:Key="StandardTexts"
            Source="C:\StandardText.xml"
            XPath="/StandardTextData"
        </XmlDataProvider>
    </Window.Resources>

    <ComboBox>
        x:Name="Combobox1"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource StandardTexts}, XPath="StandardTextInfo"}"
        SelectedItem="{Binding SelectedItem, ElementName=ComboBox3, Mode=OneWay}"
        # SelectedValue: no need to be defined
        # SelectedValuePath: no need to be defined
        DisplayMemberPath="{Binding ElementName=Combobox2, StringFormat=@{0}, Path=SelectedValue}"
    </ComboBox>

    <ComboBox>
        x:Name="Combobox2"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource Languages}, XPath="LanguageInfo"}"
        SelectedValue="{Binding Prop[LanguageName].value}"
        SelectedValuePath="@LanguageName"
        DisplayMemberPath="@LanguageName"
    </ComboBox>

    <ComboBox>
        x:Name="Combobox3"
        IsEnabled="{Binding CreateMode}"
        ItemsSource="{Binding Source={StaticResource StandardTexts}, XPath="StandardTextInfo"}"
        SelectedItem="{Binding SelectedItem, ElementName=ComboBox1, Mode=OneWay}"
        # SelectedValue: no need to be defined
        SelectedValuePath="@StandardTextNumber"
        DisplayMemberPath="@StandardTextNumber"
    </ComboBox>

    </WPF:MainWindow>

Finally not so much modifications to get the expected result. The main points were:

-understand the purpose of SelectedValue and SelectedValuePath attributes

-the binding syntax StringFormat=@{0}

 

Questions 2 to 5 are now meaningless.

 

Many thanks to BAI Xuesong of BEIJING RNL SOFTWARE SCIENCE & TECH CO.LTD who provided the solution!

 

Best regards.

 

0 Likes