【问题标题】:Application Version Selector implementation应用程序版本选择器实现
【发布时间】:2014-10-27 13:41:09
【问题描述】:

我在我的 windows 8 机器上安装了以下版本的 R

•   R-3.0.0
•   R-3.0.1
•   R-.3.0.2
•   R-3.1.1

我需要使用 ComboBox 控件创建简单的 WPF 应用程序来选择 R 版本 基于 ComboBox 选择的项目,我们必须将选择的 R 版本的目录添加到环境变量中。我尝试使用 .txt 文件包含有关 R 版本详细信息和安装目录的信息。但是我达不到我的要求。有没有其他方法可以实现这一目标?

我使用了带有以下代码 sn-p 的 XML 文件,文件名为 RVersion.xml

<?xml version="1.0" encoding="utf-8" ?>

<RVersions>

  <RVersion>
    <Version>R-3.0.2</Version>
    <Path>C:\Program Files\R\R-3.0.2\bin</Path>
  </RVersion>

  <RVersion>
    <Version>R-3.1.1</Version>
    <Path>C:\Program Files\R\R-3.1.1\bin</Path>
  </RVersion>

</RVersions>

我在 XAML 文件中使用了以下代码 sn-p

<Window.Resources>
        <XmlDataProvider x:Key="RData"
                         Source="F:\Big Data\Data Analytics\Layout\Layout\RVersion.xml"
                         XPath="RVersions/RVersion"/>

    </Window.Resources>

    <Grid>
        <ComboBox             
            ItemsSource="{Binding Source={StaticResource RData}}" 
            DisplayMemberPath="@Version"             
            Height="25"            
            SelectedIndex="0"  
            SelectionChanged="ComboBox_SelectionChanged"/>
    </Grid>

在这种情况下,组合框没有显示 R 版本详细信息

【问题讨论】:

  • 将版本保存在文本或 XML 文件中,将它们读入应用程序并用它们填充 ObservableCollection&lt;string&gt;,然后将其数据绑定到 ComboBox.ItemsSource 属性。添加另一个string 属性以将数据绑定到ComboBox.SelectedItem 属性... 工作完成。为什么你不能这样做?
  • 我使用了以下代码sn-p
  • R-3.0.2C:\Program Files\R\R-3.0.2\binR-3.1.1C:\Program Files\R\R-3.1.1 \bin
  • 网格>
  • 但它没有在组合框中显示版本名称

标签: c# wpf combobox environment-variables


【解决方案1】:

我通过在 DisplayMemberPath 中使用以下修改后的代码 sn-p 实现了这一点

<ComboBox             
            ItemsSource="{Binding Source={StaticResource RData}}" 
            DisplayMemberPath="Version"             
            Height="25"            
            SelectedIndex="0"  
            SelectionChanged="ComboBox_SelectionChanged"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2021-08-24
    • 2012-05-27
    相关资源
    最近更新 更多