本文介绍了WPF。从另一个页面获取文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用包含文本框的列的datagrid。我想获取其他页面的此文本框的值,并将其显示在图表上。我可以用
的方式获取这个值?

XAML

这是第二列

            <DataGridTemplateColumn Header="Data">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox x:Name="LevelsInput" Background="Coral" Width="50" MaxWidth="50" Margin="0"></TextBox>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

C#

public InherentRiskInput()
    {
        InitializeComponent();

        var tasks = new ObservableCollection<Task>();

        for (int i = 0; i < 14; i++) //39
        {
            tasks.Add(new Task()
            {
                CategoryName = Consts.Categories[0],
                SubCategory = Consts.Category1Description[i],
                Least = Consts.Category1Least[i],
                Minimal = Consts.Category1Minimal[i],
                Moderate = Consts.Category1Moderate[i],
                Significant = Consts.Category1Significant[i],
                Most = Consts.Category1Most[i]
            });

        }

        for (int i = 0; i < 3; i++)
        {
            tasks.Add(new Task()
            {
                CategoryName = Consts.Categories[1],
                SubCategory = Consts.Category2Description[i],
                Least = Consts.Category2Least[i],
                Minimal = Consts.Category2Minimal[i],
                Moderate = Consts.Category2Moderate[i],
                Significant = Consts.Category2Significant[i],
                Most = Consts.Category2Most[i]
            });
        }

        for (int i = 0; i < 14; i++)
        {
            tasks.Add(new Task()
            {
                CategoryName = Consts.Categories[2],
                SubCategory = Consts.Category3Description[i],
                Least = Consts.Category3Least[i],
                Minimal = Consts.Category3Minimal[i],
                Moderate = Consts.Category3Moderate[i],
                Significant = Consts.Category3Significant[i],
                Most = Consts.Category3Most[i]
            });
        }

        for (int i = 0; i < 7; i++)
        {
            tasks.Add(new Task()
            {
                CategoryName = Consts.Categories[3],
                SubCategory = Consts.Category4Description[i],
                Least = Consts.Category4Least[i],
                Minimal = Consts.Category4Minimal[i],
                Moderate = Consts.Category4Moderate[i],
                Significant = Consts.Category4Significant[i],
                Most = Consts.Category4Most[i]
            });
        }

        for (int i = 0; i < 1; i++)
        {
            tasks.Add(new Task()
            {
                CategoryName = Consts.Categories[4],
                SubCategory = Consts.Category5Description[i],
                Least = Consts.Category5Least[i],
                Minimal = Consts.Category5Minimal[i],
                Moderate = Consts.Category5Moderate[i],
                Significant = Consts.Category5Significant[i],
                Most = Consts.Category5Most[i]
            });
        }

        ICollectionView taskView = CollectionViewSource.GetDefaultView(tasks);
        taskView.GroupDescriptions.Add(new PropertyGroupDescription("CategoryName"));
        Table.DataContext = taskView;
    }

我试过这个,但它出现异常"System.FormatException:"输入字符串不在格式正确。"

I tried this but it rises exception "System.FormatException: 'Input string was not in a correct format."




推荐答案


这篇关于WPF。从另一个页面获取文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 03:40