Binding validation samples

Hello

I have downloaded the Winfx beta 2 (may release) and download the binding validation sample from SDK. However, I run into system IO exception because resource can not be found. The message seems to indicate that it can not find window1.baml. I check and find that window1.baml exist in debug directory. Can anyone point me to the right direction Thanks.

The following is the line where system exception occured.

System.Uri resourceLocater = new System.Uri("BindValidation;component\\window1.baml", System.UriKind.RelativeOrAbsolute);
System.Windows.Application.LoadComponent(this, resourceLocater);

Boon



Answer this question

Binding validation samples

  • Arnaut

    Hi,

    I've tested the Sample project and it works fine on my machine.

    I'm using WinFX Beta 2 on Windows Vista Beta 2

    Have you properly desinstalled previous version of WinFX There is a tool to do that: http://www.microsoft.com/downloads/details.aspx FamilyID=aae7fc63-d405-4e13-909f-e85aa9e66146&DisplayLang=en

    Bye



  • Analyst

    Try to clean the solution, re-built-it and test it again :)

  • learnerplates

    Dear Thomas

    The following is the xaml file and code behind for the sample. It appears that both the class as well as namespace in xaml are written correctly.

    <Window Background="Honeydew"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:SDKSample"
    x:Class="SDKSample.Window1"
    Title="Binding Validation Sample"
    Width = "500"
    Height = "170"
    >

    <Window.Resources>
    <c:MyDataSource x:Key="ods"/>

    <ControlTemplate x:Key="validationTemplate">
    <DockPanel>
    <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
    <AdornedElementPlaceholder/>
    </DockPanel>
    </ControlTemplate>

    <Style x:Key="tbInError" TargetType="{x:Type TextBox}">
    <Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
    <Setter Property="ToolTip"
    Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
    </Trigger>
    </Style.Triggers>
    </Style>
    </Window.Resources>


    <DockPanel>
    <TextBlock Text="Age (If you enter illegal characters or out-of-range numbers, an exclamation point and a ToolTip will appear):" FontSize="10" DockPanel.Dock="Top"/>


    <TextBox Name="tbAge" Width="50" Height="30"
    Validation.ErrorTemplate="{StaticResource validationTemplate}"
    Style="{StaticResource tbInError}">
    <TextBox.Text>
    <Binding Path="Age" Source="{StaticResource ods}" UpdateSourceTrigger="PropertyChanged" >
    <Binding.ValidationRules>
    <c:AgeRangeRule Min="21" Max="130"/>
    </Binding.ValidationRules>
    </Binding>
    </TextBox.Text>
    </TextBox>

    </DockPanel>
    </Window>

    The following is the code behind file for bindvalidation sample:

    using System;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Windows.Data;
    using System.Globalization;
    using System.Collections.ObjectModel;

    namespace SDKSample
    {
    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    }
    }

    public class MyDataSource
    {
    private int _age;

    public MyDataSource()
    {
    Age = 0;
    }

    public int Age
    {
    get { return _age; }
    set { _age = value; }
    }
    }

    public class AgeRangeRule : ValidationRule
    {
    private int _min;
    private int _max;

    public AgeRangeRule()
    {
    }

    public int Min
    {
    get { return _min; }
    set { _min = value; }
    }

    public int Max
    {
    get { return _max; }
    set { _max = value; }
    }

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
    int age = 0;

    try
    {
    if (((string)value).Length > 0)
    age = Int32.Parse((String)value);
    }
    catch (Exception e)
    {
    return new ValidationResult(false, "Illegal characters or "+e.Message);
    }

    if ((age < Min) || (age > Max))
    {
    return new ValidationResult(false,
    "Please enter an age in the range: " + Min + " - " + Max + ".");
    }

    return new ValidationResult(true, null);
    }
    }
    }

    Thanks.

    Boon


  • Robert101

    Are you sure the problem went away by reinstalling

    On my system, I get the 'Assembly '' not found' errors only if I have a XAML file open in the designer, I think it's an issue with the XAML editor.



  • Michael Fanning - MS

    Dear Nico

    You are right. The message is misleading. For some reason, this problem was caused by installation. I have tried to re-install from operating system up and everything work fine The only difference the I did is that I am using Chinese version of Windows XP previously and now I am using English version of the window XP . I am not sure whether that was the cause of the problem.

    Thanks.


  • Gomezd01

    Re: Assembly '' cound not be found

    This does not necessarily mean that your project doesn't build. I have the impression that as soon as you use assembly references in your xaml file, a lot of (bogus) errors are reported in the task list, the first one being the 'Assembly '' could not be found', the following errors being 1 error per line of xaml that references your assembly (like e.g. the reference to your ValidationRule class).

    However, your project may still compile properly. If you briefly see 'rebuild all succeeded' in the status bar, your project has compiled successfully and you can start debugging.



  • Greg M.

    Dear Thomas

    You are right. The problem is caused by installation of software component. I have tried to uninstalled the winfx and reinstall winfx and the problem still existed. endup re-install window XP and all the software components and the program compile and execute succesfully.

    Thanks a lot for your help.

    Boon


  • Anthony Yott

    Dear Thomas

    I forget to let you know that there are some xaml error during the build of bindvalidation. The following are the errors:

    1. Assembly '' cound not be found

    2. Type "c:MyDataSource" could not be found

    3. Type "c:AgeRangeRule" could not be found

    I suspect is that there were some errors in reference to clr. The following is the xmlns:c=clr-namespace:SDKSample. I have added the "assembly=BindingValidation but still have the same problem.

    Your help is deeply appreciated. Thanks.

    Boon


  • Roberto H.

    Dear Thomas

    This is the databinding sample(BindValidation) from SDK without any modification. I could not figure out why system can not find the assembly. I have try to add the assembly=BindValidation(the assembly name from the project) after the namespace but I still get the same error. I even try to use assembly=debug\BindValidation but still does not work. Could not figure out why.

    Thanks.


  • wpf314

    Looks like there is a C# class (with the namespace SDKSample) which need to be added to your project...

    Chck if you cannot find it in the sample project



  • CA_VB2005er

    I don't thinnk this is a problem with the environment.

    But it loks like to be the only cause of the problem, except a bad desinstallation of previous version of WinFX



  • IT Professional

    Dear Thomas

    Thanks for your information. I am running on Window XP professional sp2 and Winfx beta 2. Could this be caused by environment problem Do I have to do anything different in Window XP environment

    Boon


  • rajas

    Dear Thomas

    Thanks for your help.

    I have tried to clean it and rebuild it several times and the same problem exist. I have tried it on Feb CTP and the same problem exist as well.

    Thanks

    Boon


  • Fred Nie

    Your code seems correct so can you give me more informations on the first error you have:

    Assembly '' cound not be found

    Thanks



  • Binding validation samples