|
Hi,
I created a UserControl in XAML that includes a Frame. But when the application is loading the Frame source, the application throws and InvalidOperationException. This message tells me, that the class for the Frame's source couldn't be found in the given namespace. And this is true, because it doesn't use the namespace I intended. Here's a short example to illustrate the problem:
<UserControl
x:Class="foo.fooControl"
...>
<Frame Source="fooPage.xaml" />
</UserControl>
<Page
x:Class="foo.fooPage"
...>
...
</Page>
Now the application tries to find the class for fooPage in the wrong namespace, i.e. foo.fooControl.fooPage. But that's of course wrong, because it's called foo.fooPage.
Can anybody help me and show me the correct way to achieve what I want?
Thanks in advance,
Jammni+
|
|
|
|
|
Are you sure you didn't change the namespace in your code-behind?
This works fine for me:
<!-- UserControl1.xaml -->
<UserControl x:Class="WPFTester.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="128" Width="200">
<Grid>
<Frame Name="frame1" Source="Page1.xaml" />
</Grid>
</UserControl>
<!-- Page1.xaml -->
<Page x:Class="WPFTester.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1" Height="128" Width="200">
<Grid Background="SteelBlue"/>
</Page>
<!-- Window1.xaml -->
<Window x:Class="WPFTester.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTester"
Title="Window1" Height="300" Width="300">
<Grid>
<local:UserControl1></local:UserControl1>
</Grid>
</Window>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your answer. That's more or less exactly what I am doing. Only that I placed the files in some directories, so the namespace is a bit longer.
And I didn't change the namespace in the code behind files. The strange thing is, that the exception already says, that the class should be located in a different namespace - one, that doesn't make any sense to me.
Currently I load the page in the code behind file. Perhaps I get some time later this day and can break it down and post a "working" sample.
But anyway, thanks for your answer
|
|
|
|
|
Hi everybody.
In HTML we can use a written tag in somewhere of our page, with its ID and JavaScript . As you know something like this :
<script language="javascript" type="text/javascript">
var tag = document.getElementById('tagID');
var destinationTag = document.getElementById('destinationID');
destinationTag.innerHTML = tag.innerHTML;
</script>
Now I wanna do it with XAML and C#.
For example, I've already written this XAML code :
<Grid x:Name="tag">
<Rectangle Style="{DynamicResource RectangleStyleForHolydays}"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
content
</TextBlock>
</Grid>
Then I wanna write this XAML code in a container like a Grid with C#
<Grid x:Name="destinationTag">
<!-- here -->
</Grid>
Is it possible ?
Any ideas ?
Thank you.
|
|
|
|
|
AFAIK you can't embed C# in XAML.
You can, however, create child elements of your "destinationTag"
Grid using C#....is that what you need to do?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: is that what you need to do?
No, thanks I thought maybe we can do it like HTML and JavaScript.
BTW I didn't want embed C# in XAML , I've wanted to copy XAML codes with C# from a side XAML file to the other side of it.
Do u understand what I mean ?
modified on Saturday, December 27, 2008 1:27 PM
|
|
|
|
|
Actually, you can embed .NET language code within XAML by placing it within <x:code xmlns:x="#unknown"> tags. Such code is moved into the generated partial class by the compiler, and the language must match the language of the containing project (i.e. you can't embed C# in a VB proj).
While I can't think of any good reason to do this, it is possible.
Keith
|
|
|
|
|
Thanks. I didn't know that
Have any examples (or links to examples)?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
<Button Click="button_Click">Ok</Button>
<x:Code><!CDATA[
void button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
]]></x:Code>
This example is taken from WPF Unleashed by Adam Nathan. Wrapping in CDATA is not required, but avoids the need to escape less-than, greater-than, and ampersand chars.
I am not aware of any links to more examples; probably because I can't think of any instance where coding in this manner would be a good idea.
Keith
P.S. Sorry about the formatting, couldn't figure out how to embed the XAML tags properly.
|
|
|
|
|
Thanks Keith. Much appreciated.
I just wanted to see what it looked like, and it really works!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi! I am a WPF beginner.
I just want to make an UI using WPF for an old unmanged Application coded by C++.
I want to using CCW(Com Callable Wrapper) between the managed and unmanaged world.
Following requirement is needed:
1. To keep the app unmanaged except UI;
2. To play video stream from the unmanaged app in WPF UI.
Best wishes for all and Merry chrismas!
Any help or hints are greatly appreciated!
Lance
|
|
|
|
|
|
Thank you for your reply!
I will take your suggestion into account and research it.
I will share my experience if I get any solution.
modified on Monday, December 29, 2008 2:54 AM
|
|
|
|
|
Ok,
keep in touch
that's my mail: terrasi.carmelo@gmail.com
Bye and Happy New Year
|
|
|
|
|
hi All,
I am Currently Working on Wpf And WinForms using SCSF. Any one can please help me in this ,how to Develop The Themes Concept in Wpf or Win application .If any one knows Articles please FWD the Links it helps lot.
Thanks And Regards,
Guru
|
|
|
|
|
|
Hi Friends,
I am new to WPF programming, please help me out with the following Issue:
The text in the TextBox are separated,, i.e, like N 23°23.65, here User enters N first, after that he should press Tab to edit the next field (i.e, Degrees field) and then again press tab to edit next field (minutes field)....
Kindly help me...
Thanks in Advance...
|
|
|
|
|
Try this:
<StackPanel Orientation="Horizontal">
<TextBox x:Name="Northing" />
<TextBlock Text="°" />
<TextBox x:Name="Degrees" />
<TextBlock Text="." />
<TextBox x:Name="Minutes" />
</StackPanel>
|
|
|
|
|
Hi Bro,
Thanks for the reply...
Also i have to Data Bind this into a single field in the Dataset... How can i do this??? please help me out with this issue...
|
|
|
|
|
Hi
I am unable to place a checkbox in the header of the column in datagrid.
plz help me...
Thanks
Satish
|
|
|
|
|
You can customize the Header Template. You can easily find out the header template in Blend.
|
|
|
|
|
Is there any idea/code to make map maker(earth surface rendering with lights and clouds) using wpf?
|
|
|
|
|
I doubt there's any samples available in WPF. Typical applications that do this tend to use fractal mathematics to generate random heightmaps which get transformed into terrains. You might want to google terrain mapping directx to get started.
|
|
|
|
|
hello everbody;
i want a help for a black game codes using silverlight and c# in this week,this is my lesson project and i will give it at the end of this week,is somebody help me
|
|
|
|