Hello. I am trying to make a small WPF app that will let me view images and text contained in an xml document. I have all the binding set up. Now I am trying to find a way to load a new xml file (same schema). I am trying to use the OpenFileDialog to specify the source property of the XmlDataProvider shown in my XAML to do this. The app compiles no problem, but nothing changes when I “open” a new xml file. Any help would be great!
//Here is the C# code behind
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml;
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 Microsoft.Win32;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
//Saves new XML data added to text boxes
private void write_XML_record(object sender, RoutedEventArgs e)
{
}
//Close the app
private void Close_XML_Writer(object sender, RoutedEventArgs e)
{
Window.Close();
}
//Uses OpenFileDialog to specify the source property of XmlDataProvider
private void Import_Metadata_XML(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "XML Files (Metadata.xml)|*.xml";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = false;
bool? userClickedOK = openFileDialog1.ShowDialog();
if (userClickedOK == true)
{
string filename = openFileDialog1.FileName;
XmlDataProvider MetadataDS = new XmlDataProvider();
MetadataDS.Source = new Uri(filename);
}
}
//hook up to scroll bar to cycle through XML records
private void JumpToPreviousXML(object sender, MouseButtonEventArgs e)
{
}
//hook up to scroll bar to cycle through XML records
private void JumpToNextXML(object sender, MouseButtonEventArgs e)
{
}
}
}
//Here is the XAML related to the XmlDataProvider
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication2.Window1"
x:Name="Window"
Title="XML Writer"
Width="640" Height="400" Icon="PI Icon.png" Background="#FFCECECE" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">
<Window.Resources>
<XmlDataProvider x:Key="MetadataDS" Source="C:\Documents and Settings\Psychman\My Documents\Expression\Deep Zoom Composer Projects\CannonballImages_Test\source images\OutputSdi\collectiontest2\DeepZoomProjectWeb\ClientBin\GeneratedImages\Metadata.xml" d:IsDataSource="True"/>