|
I'm getting a XamlParseException on startup of my WPF application when compiled for debug. If I rebuild the solution, the problem goes away until the next time I start VS2008 with this solution.
Tracing the inner exceptions shows that the exception is being thrown because it can't locate a resource dictionary being loaded through a relative pack URI, like this:
ResourceDictionary table = new ResourceDictionary();
table.Source = new Uri(@"/Delta;component/Framework.xaml",UriKind.Relative); I've Google'd this, but not found anything that specifically points at this problem. I believe it's a bug involved in using the "Visual Studio hosting process", but I'm not sure.
Has anyone else seen this?
Software Zen: delete this;
|
|
|
|
|
"Delta" is the assembly name and Framework.xaml is in that assembly, right?
The build action for Framework.xaml (in the Delta project) should be "Page".
If the above are correct, then I'd say there's malformed XAML somewhere in
Framework.xaml.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the reply, Mark. The build action for Framework.xaml is indeed Page. Here's the source for Framework.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String x:Key="DeltaCommon.PrintView_Unwind">Unwind</s:String>
<s:String x:Key="DeltaCommon.PrintView_Cabinet">Cabinet/{0}</s:String>
<s:String x:Key="DeltaCommon.PrintView_Rewind">Rewind</s:String>
<s:String x:Key="DeltaCommon.SetupView_Rewind">Rewind</s:String>
</ResourceDictionary> I have a hard time believing this is a problem with the XAML, given that a 'rebuild solution' corrects the problem until the next time Visual Studio is started with this solution.
I no longer believe the Visual Studio hosting process is involved, since disabling it has no effect. The exception is still thrown the first time the application runs after Visual Studio loads the solution. The exception stops being thrown after the solution is rebuilt.
Software Zen: delete this;
|
|
|
|
|
What are you doing with the dictionary "table" after you set its Source?
Also, do you have all 2008 service packs and hotfixes installed?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I've got service pack 1 installed. I've looked through the hotfixes, and don't see any that seem applicable. I'm leery of applying them all without a compelling reason to do so.
I'm using the resource dictionary to look up user text strings, similar to the old STRINGTABLE entries in native development. Eventually these will be translated into other languages. The look-up happens like this:
string text = table["DeltaCommon.PrintView_Cabinet"];
Software Zen: delete this;
|
|
|
|
|
I'm unable to get anything bad to happen loading your dictionary and retrieving
values the same way. I don't see anything that shouldn't work either.
Is the dictionary XAML in a separate DLL from the code that loads it?
Seems more like a module or project related issue than a WPF issue since
it works after a rebuild...
I haven't a clue, sorry
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Is the dictionary XAML in a separate DLL from the code that loads it?
Hmm. Actually, yes. The code that loads the dictionary is in a utility class in a class library. The utility class constructor is passed a string that is the relative URI of the resource dictionary XAML. I tried changing to using an absolute URI, and that made no difference.
This problem appears to happen only when running under the debugger. A release compile works fine.
Thus far this seems to be an annoyance issue only, so I'm probably going to let it go for the time being. Thanks for all your help.
Software Zen: delete this;
|
|
|
|
|
Most people use 96 DPI, but occasionally people set this to 120 DPI (or even higher), especially with high resolution monitors that display at greater than 100 DPI. This number is easy to get under Win32 ("LogPixels") and I've done it for years. But I haven't been able to find out what .NET API delivers this number. This is such an important parameter that there must be a simple API to get it under .NET. Does anyone know what it is? This is especially important from Vista onward which doesn't believe in physical pixels, but merely device independent units.
Matthew MacDonald's Pro WPF in C# 2008, chapter 1, has a good discussion of device independent DPI scaling but nowhere does he say how to obtain this crucial number. I need the number because I have to scale the numbers that come back from the monitor enumeration, which specifies, x,y, height, and width, to fill the screen with a bitmap. All these numbers have to be scaled back by a factor 96/x, where x is the DPI Scaling number.
If worse comes to worse, I'll use Interop services to get the number, but I cringe every time I do that, thinking that I've just missed something in .NET.
I've been told how to do this with a .NET Forms application, but I can't find anything comparable for WPF. The suggestion was as follows:
Graphics g = this.CreateGraphics();
MessageBox.Show(g.DpiX.ToString() + Environment.NewLine + g.DpiY.ToString());
g.Dispose();
g = null;
I can also get this number from the Registry: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI]"LogPixels" but that's even more of a hack than Interop Services. The cleanest way would be through a .NET API.
|
|
|
|
|
|
Fantastic! If it works. Won't find out for a while as I'm right in the middle of something else, but hope to get to it by the end of the day. Good job of researching.
Ian Shlasko wrote: http://blogs.msdn.com/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx[^]
Not quite as simple as I expected, but it's in the framework.
But it's simpler than contaminating my WPF with Windows Forms stuff!
|
|
|
|
|
It does work! The beauty of this solution is that it is device-specific, so if Microsoft ever does get around to supporting individual DPI Scalings per monitor, this code will work without change.
Consider the following code snippet:
_left = Monitor.Rect.left;
_top = Monitor.Rect.top;
_width = Monitor.Width;
_height = Monitor.Height;
Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
double dpiX = m.M11;
double dpiY = m.M22;
_left /= dpiX;
_top /= dpiY;
_width /= dpiX;
_height /= dpiY;
The original values of _left, _top, _width and _height are the direct result of the monitor properties of the monitor the code is going to display images on. dpiX and dpiY are then the DPI scaling factors of the X and Y directions of that monitor. for 96 DPI (the standard) the values are 1.0. For 120 DPI, the values are 1.25. So I just scale the four monitor dimensions and Voila! Absolute perfection for this particular monitor.
End of story.
|
|
|
|
|
My problem is 3 fold.
1. I'm not sure what is exactly the logical tree and its impact on WPF. what's in it?
I'm using mole to drill down my UI and, to my surprise, big chunk of it seems to be missing (i.e. plenty of my object hierarchy is not there)...
2. I also wonder how does the logical tree affect DependencyProperty. I was trying to have some inherited dependency property in my object. But they were not inherited. I suspedted it might be because of the (more empty that it should) logical tree and, after some googling, I found out that inherited attached property cross logical tree boundary, which it did. But it still looks like magic to me, can anyone clarify?
3. I have a simple test application (below) but when I explore my logical tree of my window (with a break point in the button event handler) (thanks Mole for making it easy!) it stops at the ItemsControl, which has no logical child!
How could I make sure my ItemsControl do have logical child?
Here is a sample test code
Window1.xaml
<Window<br />
x:Class="LC.Window1"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
xmlns:local="clr-namespace:LC"<br />
Title="Window1" Height="300" Width="300"><br />
<DockPanel><br />
<br />
<Button Click="ButtonClick" Content="Foo" DockPanel.Dock="Bottom"/><br />
<br />
<ItemsControl x:Name="pavlova"><br />
<ItemsControl.ItemsPanel><br />
<ItemsPanelTemplate><br />
<Canvas<br />
HorizontalAlignment="Stretch" <br />
VerticalAlignment="Stretch"<br />
/><br />
</ItemsPanelTemplate><br />
</ItemsControl.ItemsPanel><br />
<ItemsControl.ItemTemplate><br />
<DataTemplate DataType="{x:Type local:Boo}"><br />
<Border<br />
BorderBrush="Black"<br />
BorderThickness="1"<br />
CornerRadius="3"<br />
><br />
<TextBlock Text="{Binding Text}"/><br />
</Border><br />
</DataTemplate><br />
</ItemsControl.ItemTemplate><br />
<ItemsControl.ItemContainerStyle><br />
<Style><br />
<Setter Property="Canvas.Top" Value="{Binding X}"/><br />
<Setter Property="Canvas.Left" Value="{Binding Y}"/><br />
</Style><br />
</ItemsControl.ItemContainerStyle><br />
</ItemsControl><br />
<br />
</DockPanel><br />
</Window>
Window1.xaml.cs
public partial class Window1 : Window<br />
{<br />
public Window1()<br />
{<br />
InitializeComponent();<br />
<br />
var l = new List<Boo>();<br />
l.Add(new Boo { X = 1, Y = 1, Text = "sahjk" });<br />
l.Add(new Boo { X = 1, Y = 100, Text = "ew hyhj" });<br />
l.Add(new Boo { X = 25, Y = 150, Text = "egje r09uy798" });<br />
<br />
pavlova.ItemsSource = l;<br />
}<br />
<br />
private void ButtonClick(object sender, RoutedEventArgs e)<br />
{<br />
<br />
}<br />
}<br />
Boo.cs
public class Boo<br />
{<br />
public double X { get; set; }<br />
public double Y { get; set; }<br />
public string Text { get; set; }<br />
}<br />
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
i want to serialize the collection class in wcf to be sent to wpf application and used there.
i am adding CollectionDataContract attribute to the class and DataMember attribute to the method but not getting the result. Can one give me some link where i can get the exact procedure .
|
|
|
|
|
be sure that your class is public & you marked the class as [DataContract]
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
no we have to take CollectionDataContract attribute and then how to do it i am not getting.
|
|
|
|
|
Are you using it for your own serializable collection? You can only apply it to a valid serializable collection recognised by System.Runtime.Serialization.DataContractSerializer .
If your class is a normal class (not a collection), then you have to use DataContract attribute for that...
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
You would be better off including some code in order to help people help you.
|
|
|
|
|
What do you mean by collectiondatacontract ?
See that [DataContract] and [DataMember] attribute are added properly.
MJ
http:\\v2attechhorizon.blogspot.com
vijaykishan
|
|
|
|
|
Hi,
I am doing an Windows Application using XAML ,WPF in C#.
I have 2 radio buttons called "WriteData" and "ReadData".
when writeData is selected, I need groupbox with a textbox and browse button inside it to be displayed at a particular location, (this i have already designed in UI..)
<GroupBox Header="Browse Data" Name="grpBrowseData" Height="78" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1030">
<Grid Name="grdBrowse" Height="60" Width="1030">
<Button x:Name="btnBrowseButton" Margin="0,7.5,45,20" Content="Browse" Click="BrowseButton_Click" HorizontalAlignment="Right" Width="111" />
<TextBox x:Name="txtBxBrowseTB" Margin="46,13.993,185,17.5" Text="TextBox" TextWrapping="Wrap" TextChanged="BrowseTB_TextChanged" ></TextBox>
<Label HorizontalAlignment="Left" Margin="-1.25,8.75,0,15" Name="label1" Width="47.5" FontSize="13" VerticalContentAlignment="Center" HorizontalContentAlignment="Center">Path:</Label>
</Grid>
Now, if I select "ReadData" radio button, a combo box should be visible in the SAME LOCATION where the above groupbox is displayed, the xaml code for this
<GroupBox Header="Select the Project" Name="grpSelectProject" Height="78" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1030" Visibility="Visible" Margin="-1030,0,0,0">
<Grid Name="grdSelectProject" Height="60" Width="1030">
<Label HorizontalAlignment="Left" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="0,11.662,0,20.825" Width="95.103">Select the Project</Label>
<ComboBox Margin="119.952,13.994,493.969,16.66"></ComboBox>
</Grid>
</GroupBox>
so, how do I make only one visible as per the radio button selected.
In the ReadData_click event i tried to make other groupbox invisble. but I wasnt able to do that. please help me.
Thanks
Ramm
|
|
|
|
|
based on the radio button click event set the Visibility property of the groupbox to collapsed.
if your groupbox name is grb1 then use:
grb1.Visibility = Visibility.Collapsed;
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
You could always put a trigger element in your XAML.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
Can anyone suggest me from where I can get an advanced Flip Book control for my WPF 3.5 SP1 application?
Any help regarding the same is highly appreciable.
Thanks in advance.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
There's this[^] control.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I'm working with the Telerik WPF controls, and I'm trying to derive a new class from one of their controls. I'm adding some visual components (a titlebar and a toolbar) to their grid view template, and I want to be able to change some of the properties of those components via XAML. I've accomplished all of this, but I have a problem.
My derived class contains the attached property stuff, and the way that these properties are "set" is via the OnApplyTemplate() method. However, if I add that method to the class, the grid refuses to show the data items. This is true regardless of what's in the method (even if it's just a call to base.OnApplyTemplate() ). If I *don't* include that method, the attached properties aren't applied.
I don't understand why this might be happening. I used reflector to see what the RadGridView is doing, but it's just calling *it's* base method, and setting some sample data if there is no data bound to the grid.
So the problem is with the OnApplyTemplate() method. Is there another way to apply attached properties or am I just doing this wrong?
EDIT ====================================
I approached the problem from a different direction. It's a bit bulkier than deriving from Telerik's class, but I got it to work. I ended up creating my own custom control that is just the stuff I wanted to add to the Telerik-derived control. This allowed me to play with the code without hosing up their RadGridView. It took about 6 hours to do the whole thing, but it now works. I'm not happy with what I've ended up doing because I just know what I really wanted to do is entirely possible, but I simply don't know the magic words to make it go. I need to move on with the project, so I'm going to leave it as is, and maybe poke at it in my spare time.
Telerik was of no help at all. Instead of trying to do what I described (since they're evidently much better at WPF than I am), they pestered me for sample code, and even suggested that I create a UserControl , of all things. A user control is fine if you only need one, but I have DOZENS of grids in this application, and I'm not going to write a UserControl for each one.
I'm already not fond of their stuff because their ideas on theming are so bizarre as to morph into major suckage. Oh yeah - the vertical scrolling on their grids are hopelessly screwed up.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Monday, July 20, 2009 6:22 AM
|
|
|
|
|
Hi All,
I wrote I silverlight application a while back and I needed to convert it into a WPF executable. I did this in about a day, but I have already spent a couple of days trying to figure out a way for the wcf application to keep my session variables.
Example of what I am doing:
WPF Client:
wcl.CheckUserAsync("username","password");
WCF:
public bool CheckUserAsync(string userName, string password)
{
if (isValid(userName, password))
{
System.Web.HttpContext.Current.Session["userName"] = userName;
return true;
} else {
return false;
}
}
WPF Client:
wcl.GetUserNameAsync();
WCF:
public string GetUserName();
{
return System.Web.HttpContext.Current.Session["userName"].toString();
}
So my problem is that System.Web.HttpContext.Current.Session["userName"].toString() = null at this point. I know that the reason this is not working in the WPF application is that I do not have a cookie where I can store the session id. I have been looking everywhere...google and books....and have not found a clear explanation of how to store the session id in a cookie in my WPF app. Can anyone help with this?
Thanks
|
|
|
|
|