|
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
|
|
|
|
|
System.Web.HttpContext is ASP.NET, not WCF. You may want to understand how
WCF interacts with ASP.NET.
There's some more info here: WCF Services and ASP.NET[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the reply Mark,
I understand that it is asp .net. I have the service running in asp net compatibility mode. I should have that made that more clear, sorry.
What I am trying to mimic in my wpf executable is the retrieval of the session id from asp .net, save that session in a cookie, retrieve it and send that session id back on my next call to the server.
Thanks
|
|
|
|
|
jeremyadell wrote: What I am trying to mimic in my wpf executable is the retrieval of the session id from asp .net, save that session in a cookie, retrieve it and send that session id back on my next call to the server.
In ASP.NET compatibility mode that should happen automatically if
you set AllowCookies to true on the client service binding.
You want to do that manually?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
Thanks a ton for your help. Adding the allowCookies="true" attribute to my binding fixed it. The silverlight to WPF conversion works perfectly now. This was my first executable that called a web service and needed cookies. I searched for days online trying to figure out how. Amazing how simple it was.
|
|
|
|
|
I did this a couple years ago under MFC but it required going to COM, C++ code like this:
HRESULT Sheet::UpdateLink(CString strSourcePath, CString strLinkPath,
CString strDesc, CString strArguments)
{
HRESULT hres;
IShellLink* psl;
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
LPOLESTR oleLinkPath = (LPOLESTR)(LPCTSTR)strLinkPath;
hres = ppf->Load(oleLinkPath, STGM_READWRITE);
if (FAILED(hres))
{
}
hres = psl->SetPath(strSourcePath);
hres = psl->SetDescription(strDesc);
if (strArguments.GetLength())
{
hres = psl->SetArguments(strArguments);
}
hres = ppf->Save(oleLinkPath, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
I'd like to think those days are history, but after researching for a couple hours, I couldn't find a single mention about how to do this under WPF, or under .NET in general. Is there a way?
If I do have to use COM, how difficult would it be to wrap the above UpdateLink function into something I could call from WPF?
So far I've avoided going to unmanaged code by using System.Runtime.InteropServices stuff. I've done lots of neat stuff with functions in shell32.dll, like applying bitmaps to buttons and labels, sending files to the recycle bin (using SHFileOperation), calling ShellExecuteEx, etc., but no COM stuff. Is there a nightmare in my future if I try to do this?
|
|
|
|
|
WPF has nothing to do with it. You do it by copying shortcuts to the right locations, same as for any C# app.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I thought I had to programmatically create shortcuts in MFC using COM. If so, how do I do it in .NET? This is how I did it in my code I originally posted:
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
LPOLESTR oleLinkPath = (LPOLESTR)(LPCTSTR)strLinkPath;
hres = ppf->Load(oleLinkPath, STGM_READWRITE);
if (FAILED(hres))
{
}
hres = psl->SetPath(strSourcePath);
hres = psl->SetDescription(strDesc);
if (strArguments.GetLength())
{
hres = psl->SetArguments(strArguments);
}
hres = ppf->Save(oleLinkPath, TRUE);
ppf->Release();
It sounds like you think that original MFC/COM code was way overkill and that I made a mountain out of a molehill.
Give me a coding example of the extremely simple way you have in mind.
|
|
|
|
|
private void urlShortcutToDesktop(string linkName, string linkUrl)
{
string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
using (StreamWriter writer = new StreamWriter(deskDir + "\\" + linkName + ".url"))
{
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=" + linkUrl);
writer.Flush();
}
}
I found this on the web. deskDir is the folder to which you need to write a shortcut to your program.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
That's absolutely wonderful if it works. I'll give it a try and let you know how it works out.
|
|
|
|
|
Thanks a lot, Christian. Magic that I didn't know about: "[InternetShortcut]". I Googled for that and found out how to extend your code to get the icon out of the linkUrl. Here is my code combining your suggestion with the extension:
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=" + linkUrl);
writer.WriteLine("IconFile=" + linkUrl);
writer.WriteLine("IconIndex=0");
writer.Flush(); The next thing to do is to programmatically add links to the Quick Launch bar. For that you have to get the path to the Quick Launch folder. I do that in the following function, which is like yours, except it generates a path to the Quick Launch folder and also establishes the icon:
private void ShortcutToQuickLaunchFolder(string linkName, string linkUrl)
{
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string quickLaunchFolder = appData + @"\Microsoft\Internet Explorer\Quick Launch";
using (StreamWriter writer = new StreamWriter(quickLaunchFolder + "\\" + linkName + ".url"))
{
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=" + linkUrl);
writer.WriteLine("IconFile=" + linkUrl);
writer.WriteLine("IconIndex=0");
writer.Flush();
}
} Everything works beautifully! Hope this is useful for other people.
|
|
|
|
|
I discovered a big limitation that .lnk files do not have. The URL File Format apparently does not support command line parameters, so if a program has several modes of operation, you're stuck. I tried specifying a batch file to invoke the program, where the batch file contains the full path of the executable plus a command line parameter and it didn't work.
|
|
|
|
|