5 Replies - 1951 Views - Last Post: 02 March 2011 - 08:13 AM Rate Topic: -----

#1 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

What's the signifigance of the colon in XAML

Posted 01 March 2011 - 04:13 PM

I'm very new to WPF. I'm proficient at C#, yet I'm having trouble making sense of all the xaml stuff. What do colons mean? I just downloaded another new wpf tutorial and this one has seemingly random colons strewn about, and I can't even copy and paste the code from that project into another one with out running into an error (Error 1 The tag 'StatusList' does not exist in XML namespace 'clr-namespace:SalesForce'.).

Here's the working code:

<Window x:Class="ComboBoxDGWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ComboBox DataGrid WPF" Height="300" Width="616"
    xmlns:staticData="clr-namespace:ComboBoxDGWPF"
    xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit">
    
    <window.Resources>
        <staticData:StatusList x:Key="StatusList"/>
    </window.Resources>
    
    <Grid>
        <my:DataGrid x:Name="dgData" AutoGenerateColumns="False">
...
...



So first off, what does "x:Class=" mean? And what about when we see "x:Name=" or "x:Key" or "xmlns:x" (the x is on the other side, what's going on here?)??

Second, what's the deal with the "my:" prescript? I can't seem to use it in my own solutions, and I can't figure out where to define it correctly. The full source can be downloaded from here if interested.

Is This A Good Question/Topic? 0
  • +

Replies To: What's the signifigance of the colon in XAML

#2 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: What's the signifigance of the colon in XAML

Posted 01 March 2011 - 04:17 PM

From what I can gather about XAML, the ':' operand is a lot like using '.' in C#... Don't take my word for it though.

[Edit] It the ':' is prefixing.
At the top of your code you can see xmlns:x, that assigns 'x' to an xml scheme, then using 'x:' allows access to said schema, it's all in here, pay special attention to the "the x: prefix" and "Custom Prefixes and Custom types in XAML" paragraphs.

[Edit2] Further from this, the 'my:' prefix will have been set by assigning xmlns:my="url" at the top of the code.

[Edit3] Further to the above, this line: xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"

[Edit4] Defined correctly here:
<Window x:Class="ComboBoxDGWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ComboBox DataGrid WPF" Height="300" Width="616"
    xmlns:staticData="clr-namespace:ComboBoxDGWPF"
    xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit">


Line 6.

This post has been edited by pryogene: 01 March 2011 - 04:24 PM

Was This Post Helpful? 2
  • +
  • -

#3 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: What's the signifigance of the colon in XAML

Posted 01 March 2011 - 04:59 PM

Thanks for the quick reply, this is very helpful. I had a minor typo that was causing that error, but I'm still not quite able to use the my prefix like I'd expect.
Was This Post Helpful? 0
  • +
  • -

#4 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: What's the signifigance of the colon in XAML

Posted 01 March 2011 - 05:39 PM

No problem.

First of all, how are you trying to use it - code and an explanation will be useful so I can see what you're trying to do.
Second of all, make sure you're familiar with the schema you're linking 'my' to.
Was This Post Helpful? 0
  • +
  • -

#5 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: What's the signifigance of the colon in XAML

Posted 01 March 2011 - 07:27 PM

I fixed it, I needed to add a reference to a dll called WPFToolkit which came with the original project. I'm really just exploring, so I'm not quite sure what I can do with it yet, but when I saw the prefix "my" it made me think that it was somehow creating a new control class the way you can in C# (eg custom controls). But that was just my first hypothesis. After some googling, I'm under the impression that .NET 3.5 must have been lacking stuff like a dataGrid control, and so the WPFToolkit added those missing controls. I'm doing this in 4.0 so I'm thinking I don't need to rely on <my:DataGrid> and can rewrite the tags straight to <DataGrid> as needed without complicating my project with references.

Here's the source I'm describing if you're interested in checking it out. Note that the dll they provided may or may not be authentic, I didn't check it out.

This post has been edited by NotarySojac: 01 March 2011 - 07:29 PM

Was This Post Helpful? 1
  • +
  • -

#6 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: What's the signifigance of the colon in XAML

Posted 02 March 2011 - 08:13 AM

View PostNotarySojac, on 01 March 2011 - 07:27 PM, said:

I fixed it, I needed to add a reference to a dll called WPFToolkit which came with the original project. I'm really just exploring, so I'm not quite sure what I can do with it yet, but when I saw the prefix "my" it made me think that it was somehow creating a new control class the way you can in C# (eg custom controls). But that was just my first hypothesis. After some googling, I'm under the impression that .NET 3.5 must have been lacking stuff like a dataGrid control, and so the WPFToolkit added those missing controls. I'm doing this in 4.0 so I'm thinking I don't need to rely on <my:DataGrid> and can rewrite the tags straight to <DataGrid> as needed without complicating my project with references.

Here's the source I'm describing if you're interested in checking it out. Note that the dll they provided may or may not be authentic, I didn't check it out.


Honestly, you're the first person I've ever tried to help on here that's actually taken a stab at helping themselves along side me. Kudos to you, I'm impressed.
As for custom control classes, no, WPF still works the same way, it all just looks a little different - C# is the language, WPF is the technology, it's essentially just a fancy version of Windows Forms.

When using the WPFToolkit (which I recommend you go up to codeplex and search for, as you may have gotten an older assembly), you should be able to just do <DataGrid>, my recommendation would be to explore both drag & drop + properties window and hard-coded XAML methods of UI construction - good knowledge of both is always good.

Otherthan that, happy coding!! (I've +'d you for trying to fix your own problem. I'm chuffed :P)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1