|
The "easiest" way to do this would be to create a composite model, which is a model of all of the parts added together - you would then add this. This is not a trivial task, because you want to maintain a hierarchy of objects, plus the transformations that need to be applied to them to create the final state.
"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
|
|
|
|
|
Hi,
I have to add a "Search Box" with a DropDown Button for searching the books.
This dropdown button should have an arrow pointing downwards and the search textbox next to it. so, wen i click on dropdown button, i should get few options (like team, personal, e........) If i select Team then the text "Search in Team" should be displayed in the textbox. A small magnifier for the searchbox will be available too.
I am using C#, XAML..its WPF app
Please help me.
Thanks
Ramm
|
|
|
|
|
So, what have you done so far?
"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
|
|
|
|
|
Hi,
Currently, I have added the button and textbox to the window and added this code to it.
<pre> <Button x:Name="btnSearch" Content="TWB" Width="60" HorizontalAlignment="Left" Height="30" Click="btnSearch_Click"></Button>
<Popup x:Name="btnSearchPopUp" Margin="60,-30,0,0" Width="45" HorizontalAlignment="Left"
PlacementTarget="{Binding ElementName=btnSearch}"
PopupAnimation="Fade">
<ListBox x:Name="TransitionKind" Width="75">
<ListBoxItem Content="TWB"/>
<ListBoxItem Content="PWB"/>
<ListBoxItem Content="Other"/>
<ListBoxItem Content="None"/>
</ListBox>
</Popup></pre>
in the c# code
<pre> private void Window_Loaded(object sender, RoutedEventArgs e)
{
btnSearch.Click += new RoutedEventHandler(btnSearch_Click);
TransitionKind.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(TransitionKind_SelectionChanged);
}
void TransitionKind_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
btnSearch.Content = ((ListBoxItem)TransitionKind.SelectedItem).Content;
btnSearchPopUp.IsOpen = false;
txtBxSearch.Text = "Search " + (string)btnSearch.Content;
}
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
btnSearchPopUp.IsOpen = true;
}
</pre>
actually this provides me the dropdown of the button, but a small traingle kind of thing on the button indicating the dropdown and magnifying glass is not included.
Please help me, the more better way to do this.
Thanks
Ramm
|
|
|
|
|
I have tried the application that is listed
Silverlight Auto Complete Treeview[^]
It seems to be a good solutions accessing the View Model in a MVVM application using the treeview. The core of this article is based on Bea Stollnitz's solution to treeview expansion in Silverlight. However, it does not like to get binded using DataContext and ItemsSource in XAML. Does anybody has come up with a solution?
|
|
|
|
|
Hello,
Are you setting Model to the datacontext of MainPage? If yes, you will need to load the xml file from the constructor of that Model class and will add to add one more property in Model class.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
it was just a long day...thanks though.
|
|
|
|
|
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
|
|
|
|