Setting local namespace in xaml file

D

DeanB

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);
}
}
}
}
 
D

DeanB

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top