By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Setting local namespace in xaml file

P: n/a
Please excuse my ignorance here as I have not used WPF for long, but
what is the statement that tells what the "local:" identifier is that
allows a window event to call a function in a .cs file?

Here is the top of a window definition in xaml: I've marked the area
in question with ?????. I have to call the TypeDirectoryValidationRule
function from within the xaml code. I'm also confused on what the
"SomePath" string is supposed to be for.

Thanks for any help!.
<Window x:Class="SlideShowCS.fTypeDirectory"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local=?????????????????????????????????????? ?
Title="Type Directory Path" Height="164" Width="566" >
<Grid >
<Grid.Resources>
<Style TargetType="{x:Type Label}"><Setter Property="Margin"
Value="0,3,5,5"></Setter></Style>
<Style TargetType="{x:Type Grid}"><Setter Property="Margin"
Value="0,0,0,5"></Setter></Style>
<Style TargetType="{x:Type TextBox}"><Setter Property="Margin"
Value="5,5,5,5"></Setter></Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Name="label1" >Please enter a directory containing
your images:</Label>
<TextBox Grid.Row="1" Name="textBox1">
<TextBox.Text>
<Binding Path="SomePath">
<Binding.ValidationRules>
<local:TypeDirectoryValidationRule></
local:TypeDirectoryValidationRule>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</Grid>
</Window>
....

And here is the cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Globalization;
using System.IO;
namespace SlideShowCS
{
/// <summary>
/// Interaction logic for fTypeDirectory.xaml
/// </summary>
public partial class fTypeDirectory : Window
{
public fTypeDirectory()
{
InitializeComponent();
}
}
public class TypeDirectoryValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo
cultureInfo)
{
string sDirName = (string)value;
if (!Directory.Exists(sDirName))
{
string sMsg = string.Format("Directory does not exist: {1}",
sDirName);
return new ValidationResult(false, sMsg);
}
else
{
return new ValidationResult(true, null);
}
}
}
}
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 18, 4:28*pm, DeanB <deanbrow...@yahoo.comwrote:
Please excuse my ignorance here as I have not used WPF for long, but
what is the statement that tells what the "local:" identifier is that
allows a window event to call a function in a .cs file?

Here is the top of a window definition in xaml: I've marked the area
in question with ?????. I have to call the TypeDirectoryValidationRule
function from within the xaml code. I'm also confused on what the
"SomePath" string is supposed to be for.

Thanks for any help!.

<Window x:Class="SlideShowCS.fTypeDirectory"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local=?????????????????????????????????????? ?
Title="Type Directory Path" Height="164" Width="566" >
<Grid >
<Grid.Resources>
<Style TargetType="{x:Type Label}"><Setter Property="Margin"
Value="0,3,5,5"></Setter></Style>
<Style TargetType="{x:Type Grid}"><Setter Property="Margin"
Value="0,0,0,5"></Setter></Style>
<Style TargetType="{x:Type TextBox}"><Setter Property="Margin"
Value="5,5,5,5"></Setter></Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Name="label1" >Please enter a directory containing
your images:</Label>
<TextBox Grid.Row="1" Name="textBox1">
<TextBox.Text>
<Binding Path="SomePath">
<Binding.ValidationRules>
<local:TypeDirectoryValidationRule></
local:TypeDirectoryValidationRule>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</Grid>
</Window>

...

And here is the cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Globalization;
using System.IO;
namespace SlideShowCS
{
/// <summary>
/// Interaction logic for fTypeDirectory.xaml
/// </summary>
public partial class fTypeDirectory : Window
{
public fTypeDirectory()
{
InitializeComponent();}
}

public class TypeDirectoryValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo
cultureInfo)
{
string sDirName = (string)value;
if (!Directory.Exists(sDirName))
{
string sMsg = string.Format("Directory does not exist: {1}",
sDirName);
return new ValidationResult(false, sMsg);}

else
{
return new ValidationResult(true, null);

}
}
}
}- Hide quoted text -

- Show quoted text -
I found the answer. FWIW: It was:

xmlns:local="clr-reference.SlideShowCS", where SlideShowCS is the
namespace for the app. I don't know why this is not explained in any
of the books. Anyone know what clr-reference actually is?
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.