Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to subclass control?
Message
From
25/04/2008 14:56:51
 
 
To
25/04/2008 13:49:41
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01184867
Message ID:
01313187
Views:
18
>Man...Cool screens. How about showing the XAML for the body of the http://www.wordmasters.com/images/temp/cdspro2.jpg image. That's the basic layout I use in my VFP screens, so seeing that done in XAML would be very helpful. Do you mind?

It's not very clean, I still haven't settled on my naming and styling conventions for the XAML. And it's also still a work in progress.

cdsDockContent is a child of App/MainWindow/DockPanel/DockPane
<cdsc:cdsDockContent x:Class="cdsPro.cdsPayablesDetail"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:xcd="clr-namespace:Xceed.Wpf.Controls;assembly=Xceed.Wpf.Controls"
                     xmlns:cdsc="clr-namespace:CDS.WPF.Controls;assembly=cdsWPFControls" 
                     xmlns:cdsb="clr-namespace:CDS.WPF.Controls.Base;assembly=cdsWPFControls" 
                     xmlns:local="clr-namespace:cdsPro"
                     xmlns:localControls="clr-namespace:cdsPro.Controls"
                     xmlns:my="clr-namespace:System;assembly=mscorlib">
  <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
    <Grid>
      <Grid.Resources>
        <Style x:Key="EditItemLabel" TargetType="{x:Type Label}">
          <Setter Property="Padding" Value="5,10,10,2"></Setter>
        </Style>
        <Style x:Key="EditItemTextBox" TargetType="{x:Type TextBox}">
          <Setter Property="Margin" Value="5,1,5,2"></Setter>
          <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
              <Setter Property="ToolTip" 
                      Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                      Path=(Validation.Errors)[0].ErrorContent}"/>
              <Setter Property="Foreground" Value="Red"/>
            </Trigger>
          </Style.Triggers>
        </Style>
        <Style x:Key="EditItemDateBox" TargetType="{x:Type xcd:DatePicker}">
          <Setter Property="Margin"      Value="5,1,5,2"></Setter>
          <Setter Property="Height"      Value="20"></Setter>
          <Setter Property="BorderBrush" Value="#FFA5ACB2"></Setter>
          <Setter Property="BorderThickness" Value="0.9"></Setter>
          <Setter Property="Width" Value="80" />
          <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
              <Setter Property="ToolTip" 
                      Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                      Path=(Validation.Errors)[0].ErrorContent}"/>
              <Setter Property="Foreground" Value="Red"/>
            </Trigger>
          </Style.Triggers>
        </Style>
        <Style x:Key="EditItemALU" TargetType="{x:Type localControls:cdsAccountSelector}">
          <Setter Property="Margin" Value="5,1,5,2"></Setter>
          <Setter Property="Background" Value="Blue"></Setter>
          <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
              <Setter Property="ToolTip" 
                      Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                      Path=(Validation.Errors)[0].ErrorContent}"/>
              <Setter Property="Foreground" Value="Red"/>
            </Trigger>
          </Style.Triggers>
        </Style>
      </Grid.Resources>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>
      <WrapPanel Grid.Row="0">
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Pay On</Label>
          <xcd:DatePicker Style="{StaticResource EditItemDateBox}"
                          Name="txtPayOn" >
            <xcd:DatePicker.SelectedDate>
              <Binding Path="PayOn" 
                       Mode="TwoWay" 
                       UpdateSourceTrigger="PropertyChanged" 
                       ValidatesOnExceptions="True"
                       ValidatesOnDataErrors="True" />
            </xcd:DatePicker.SelectedDate>
          </xcd:DatePicker>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Pay</Label>
          <cdsb:cdsTextBox Width="100" 
                           HorizontalContentAlignment="Right">
            <Binding Path="Pay" Mode="TwoWay"
                     UpdateSourceTrigger="PropertyChanged" 
                     ValidatesOnExceptions="True"
                     ValidatesOnDataErrors="True" />
          </cdsb:cdsTextBox>
        </StackPanel>
        </WrapPanel>
        <WrapPanel Grid.Row="1">
          <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Date Received</Label>
          <xcd:DatePicker Style="{StaticResource EditItemDateBox}"
                          Name="txtDateRevd" >
            <xcd:DatePicker.SelectedDate>
              <Binding Path="Date" 
                       Mode="TwoWay" 
                       UpdateSourceTrigger="PropertyChanged" 
                       ValidatesOnExceptions="True"
                       ValidatesOnDataErrors="True" />
            </xcd:DatePicker.SelectedDate>
          </xcd:DatePicker>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Date</Label>
          <xcd:DatePicker Style="{StaticResource EditItemDateBox}"
                          Name="date">
            <xcd:DatePicker.SelectedDate>
              <Binding Path="InvoiceDate" 
                       Mode="TwoWay" 
                       UpdateSourceTrigger="PropertyChanged" 
                       ValidatesOnExceptions="True"
                       ValidatesOnDataErrors="True" />
            </xcd:DatePicker.SelectedDate>
          </xcd:DatePicker>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Date Due</Label>
          <xcd:DatePicker Style="{StaticResource EditItemDateBox}"
                          Name="txtDateDue" >
            <xcd:DatePicker.SelectedDate>
              <Binding Path="DateDue" 
                       Mode="TwoWay" 
                       UpdateSourceTrigger="PropertyChanged" 
                       ValidatesOnExceptions="True"
                       ValidatesOnDataErrors="True" />
            </xcd:DatePicker.SelectedDate>
          </xcd:DatePicker>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Account</Label>
          <localControls:cdsAccountSelector Width="280" 
                                    x:Name="txtAcctSelect" 
                                    ID="{Binding Mode=TwoWay, Path=AccountXRef}"
                                    Style="{StaticResource EditItemALU}"/>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Invoice</Label>
          <TextBox Style="{StaticResource EditItemTextBox}" 
                   x:Name="txtInvoice" 
                   Text="{Binding Path=Invoice, UpdateSourceTrigger=PropertyChanged }"
                   Width="200"/>
        </StackPanel>
        <StackPanel>
          <Label Style="{StaticResource EditItemLabel}">Amount</Label>
          <TextBox Style="{StaticResource EditItemTextBox}" 
                   x:Name="txtAmount" 
                   Text="{Binding Path=Amount}"
                   Width="100" HorizontalContentAlignment="Right" />
        </StackPanel>
      </WrapPanel>
    </Grid>
  </ScrollViewer>
</cdsc:cdsDockContent>
And the code behind.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using CDS.WPF.Controls;
using cdsProBusiness;
using cdsProBusiness.Objects;

namespace cdsPro
  {
  /// <summary>
  /// Interaction logic for cdsPayablesDetail.xaml
  /// </summary>
  public partial class cdsPayablesDetail : cdsDockContent
    {

    public cdsBillObject oBill;

    public cdsPayablesDetail(int id)
      {
      oBill = cdsProBusinessFactory.GetBill(id);
      if (id==0)
        Caption = "New Bill"; 
      else
        Caption = oBill.Entity.cdsContact.Name.Trim() + " - " + oBill.Entity.Invoice.Trim(); 
      DataContext = oBill.Entity;

      InitializeComponent();
      }
    
    public override bool IsDirty()
      {
      return oBill.IsDirty();
      }

    // TODO Move to library.
    public bool HasErrors(DependencyObject obj) 
      {
      // TODO Move to class field.
      DependencyProperty[] properties = { TextBox.TextProperty, Xceed.Wpf.Controls.DatePicker.SelectedDateProperty };
      foreach (DependencyProperty prop in properties)
        {
        BindingExpression be = BindingOperations.GetBindingExpression(obj, prop);
        if (be != null) 
          be.UpdateSource();
        }
      if ((bool)(obj.GetValue(Validation.HasErrorProperty)))
        return true;
      foreach (object item in LogicalTreeHelper.GetChildren(obj))
        {
        if (item is DependencyObject)
          {
          if (HasErrors((DependencyObject)item))
            return true;
          }
        }
      return false;
      }

    public override bool Save()
      {
      if (HasErrors(this))
        {
        System.Windows.Forms.MessageBox.Show("There are errors on the form, it cannot be saved untill they are fixed."); 
        return false;
        }
      oBill.Save();
      return true;
      }
    }
  }
Previous
Reply
Map
View

Click here to load this message in the networking platform