填充窗口的列

发布于 2024-08-19 09:02:19 字数 1884 浏览 10 评论 0原文

我想做的是在窗口中填充两列。此列将包含全局变量的名称及其路径。我在窗口中显示我需要的内容时遇到问题。

        <TabItem Header="Global Variables" GotFocus="GlobalVariablesTab_GotFocus">
           <dc:TreeListView Name="tvwGlobalVariables"  dc:ColumnLayoutManager.Enabled="True" >
                <dc:TreeListView.Columns>

                    <!--First Column. -->
                   <dc:StdGridViewColumn Header="Variable" Width="200" >

                         <dc:StdGridViewColumn.CellTemplate>
                             <DataTemplate>
                                <TextBlock TextTrimming="CharacterEllipsis"/>
                            </DataTemplate>
                         </dc:StdGridViewColumn.CellTemplate>
                    </dc:StdGridViewColumn>

                    <!-- Second Column-->
                     <dc:StdGridViewColumn Header="Result" dc:ColumnRange.IsFillColumn="True"/>

               </dc:TreeListView.Columns> 
            </dc:TreeListView> 
        </TabItem>

这是包含我需要填充的区域的选项卡。第一列用于名称,第二列用于路径。我可能也错过了一些东西。

    private void GlobalVariablesTab_GotFocus(object sender, RoutedEventArgs e)
    {
        lvGlobals.Items.Clear();
        sman = SchemaManager.SchemaManager.GetInstance();
        IEnumerator enumerator = sman.GetGlobalVariableEnumerator();
        while (enumerator.MoveNext()) 
        {
            DictionaryEntry entry = (DictionaryEntry) enumerator.Current;
            ListViewItem lvi = new ListViewItem();//new string[] {entry.Key.ToString(), entry.Value.ToString()});
            lvi.Tag = entry.Key.ToString() + entry.Value.ToString();
        }
    }

目前我有 lvi 持有这两个部分,但我需要一个部分进入第一列,另一个部分进入另一列。如果我不需要的话我就不打算保留lvi。无论哪种方式,我都需要在第一列中显示 entry.key ,在第二列中显示 entry.value 。有什么想法吗?

What I am trying to do is populate two columns in a window. This columns will have the name of the global variable and the path it to it. I am having problems displaying what I need in the windows.

        <TabItem Header="Global Variables" GotFocus="GlobalVariablesTab_GotFocus">
           <dc:TreeListView Name="tvwGlobalVariables"  dc:ColumnLayoutManager.Enabled="True" >
                <dc:TreeListView.Columns>

                    <!--First Column. -->
                   <dc:StdGridViewColumn Header="Variable" Width="200" >

                         <dc:StdGridViewColumn.CellTemplate>
                             <DataTemplate>
                                <TextBlock TextTrimming="CharacterEllipsis"/>
                            </DataTemplate>
                         </dc:StdGridViewColumn.CellTemplate>
                    </dc:StdGridViewColumn>

                    <!-- Second Column-->
                     <dc:StdGridViewColumn Header="Result" dc:ColumnRange.IsFillColumn="True"/>

               </dc:TreeListView.Columns> 
            </dc:TreeListView> 
        </TabItem>

This is the tab that has the area I need to populate. The first column for the name and the second will be for the path. I may be missing something as well.

    private void GlobalVariablesTab_GotFocus(object sender, RoutedEventArgs e)
    {
        lvGlobals.Items.Clear();
        sman = SchemaManager.SchemaManager.GetInstance();
        IEnumerator enumerator = sman.GetGlobalVariableEnumerator();
        while (enumerator.MoveNext()) 
        {
            DictionaryEntry entry = (DictionaryEntry) enumerator.Current;
            ListViewItem lvi = new ListViewItem();//new string[] {entry.Key.ToString(), entry.Value.ToString()});
            lvi.Tag = entry.Key.ToString() + entry.Value.ToString();
        }
    }

Currently I have lvi holding both parts but I will need one part to go to the first column and the other part to the other column. I don't intend to keep lvi if I don't need it. Either way I need to get entry.key displayed in the first column and entry.value in the second. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人心善变 2024-08-26 09:02:19

我不知道 SchemaManager 是什么,所以我只是使用带有一些虚拟数据的哈希表来获取带有一些字典条目的枚举器。下面的示例代码使用常规的 WPF 列表视图,其中有两列,没有格式设置以保持简单。

XAML:

<Window x:Class="TwoColsDemo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">

    <ListView ItemsSource="{Binding Path=Data}">
        <ListView.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn Header="Key" DisplayMemberBinding="{Binding Path=Key}" />
                    <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}" />
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Window>

隐藏代码:

using System.Collections;
using System.Collections.Generic;
using System.Windows;

namespace TwoColsDemo
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            Hashtable sman = new Hashtable();
            sman.Add("Key1", "Value1");
            sman.Add("Key2", "Value2");

            Data = new List<DictionaryEntry>();

            IEnumerator enumerator = sman.GetEnumerator();
            while (enumerator.MoveNext())
            {
                DictionaryEntry entry = (DictionaryEntry)enumerator.Current;
                Data.Add(entry);
            }

            DataContext = this;
        }

        public List<DictionaryEntry> Data { get; private set; }
    }
}

I don't know what the SchemaManager is so I just used a Hashtable with some dummy data to get an enumerator with some dictionary entries. Below sample code uses a regular WPF listview with two columns with no formatting to keep it simple.

XAML:

<Window x:Class="TwoColsDemo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">

    <ListView ItemsSource="{Binding Path=Data}">
        <ListView.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn Header="Key" DisplayMemberBinding="{Binding Path=Key}" />
                    <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}" />
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Window>

Code behind:

using System.Collections;
using System.Collections.Generic;
using System.Windows;

namespace TwoColsDemo
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            Hashtable sman = new Hashtable();
            sman.Add("Key1", "Value1");
            sman.Add("Key2", "Value2");

            Data = new List<DictionaryEntry>();

            IEnumerator enumerator = sman.GetEnumerator();
            while (enumerator.MoveNext())
            {
                DictionaryEntry entry = (DictionaryEntry)enumerator.Current;
                Data.Add(entry);
            }

            DataContext = this;
        }

        public List<DictionaryEntry> Data { get; private set; }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文