WPF захватывает содержимое метки, которая заполняется Binding XPath - PullRequest
0 голосов
/ 08 января 2020

Я просто пытаюсь получить содержимое метки и поместить его в переменную. Вот мой 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

какие-либо предложения?

1 Ответ

1 голос
/ 15 января 2020

Метка может получить объект как Content.

Очевидно, в вашем случае метка получила экземпляр System. Xml .XmlAttribute

Тогда, возможно, вы можете попробовать

XmlAttribute attr = Study_Name_Ref.Content as XmlAttribute;

if(attr != null)
{
   string study_name_container = attr.Value;
}
...