WPF捕获正在使用绑定XPath填充的Label的内容

问题描述 投票:0回答:1

我只是试图获取Label的内容并将其放入变量中。这是我的Window.xaml

<Grid>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
            <Label Style="{Binding Source={StaticResource studyTitle}}">Study:</Label>
            <Label Style="{Binding Source={StaticResource studyTitle}}" Content="{Binding XPath=@Name}" Name="Study_Name_Ref"></Label>
        </StackPanel>
</Grid>

这是我的Window.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using APPIL_Importer.Methods;
using APPIL_Importer.DicomMethods;

namespace APPIL_Importer
{
    /// <summary>
    /// Interaction logic for StudyImporter.xaml
    /// </summary>
    public partial class StudyImporter : Window
    {
        ConsoleOutputStream outputter;
        public StudyImporter()
        {
            InitializeComponent();
            this.SizeToContent = SizeToContent.WidthAndHeight;

            outputter = new ConsoleOutputStream(TestBox);
            Console.SetOut(outputter);

        }

        public StudyImporter(object data) : this()
        {
            this.DataContext = data;
            this.SizeToContent = SizeToContent.WidthAndHeight;
        }

        private void Confirm_Import_On_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("This will import every series in the Import Directory. Are you sure you want to Import?", "Import Confirmation", MessageBoxButton.OKCancel);
            string study_name_container = Study_Name_Ref.Content.ToString();

            switch (result)
            {
                case MessageBoxResult.OK:
                    Console.WriteLine("Welcome Dave. Would you like to play a game?");
                    MessageBox.Show(study_name_container);
                    //ModifyDicom.ModifyCommonDicomTags(path_to_file);
                    break;
                case MessageBoxResult.Cancel:
                    MessageBox.Show("CANCEL", "Nope!");
                    break;
            }
        }
    }
}

我想捕获名为“ Study_Name_Ref”的标签的内容,但是得到的是以下内容:System.Xml.XmlAttribute

有什么建议吗?

c# wpf label
1个回答
1
投票
然后也许您可以尝试

XmlAttribute attr = Study_Name_Ref.Content as XmlAttribute; if(attr != null) { string study_name_container = attr.Value; }

© www.soinside.com 2019 - 2024. All rights reserved.