|
|
Hi,
I am new to WPF, just seeking some help.
I wanted to create a user control at which it is like an augmented panel(lets call it userpanel). There is a panel where content can be placed, and some buttons on top of the panel to do something.
What do i need to do to make what ever content i put into the usrpanel.content to go into the panel of the user control?
Right now if i insert some words into the Content of the usrpanel, the whole control blanks out with the text i punch in.
thank you
|
|
|
|
|
Use a layout control such as a Grid , StackPanel or Canvas to act as a container of your sub-controls.
/ravi
|
|
|
|
|
How can i do that? Do you have any example?
|
|
|
|
|
If I have two user controls, each with a dependency property, and both those controls are thrown into a grid, how could I bind the results of one of those properties to the other?
In short:
Control2.Customer = Control1.SelectedCustomer;
Where Customer and SelectedCustomer are the two respective DP's.
I've tried:
<local:Control1 Grid.Row="0" x:Name="customerSelector" />
<local:Control2 Grid.Row="1" Customer="{Binding ElementName=customerSelector, Path=SelectedCustomer}" />
The binding doesn't appear to do anything. A breakpoint on the setter of the Customer property never gets hit.
Any thoughts?
-Mike.
|
|
|
|
|
It won't get hit. But your value will be set. You cannot debug dependency property the normal way. To debug you have some options, See here[^]
|
|
|
|
|
Thanks! You hit the nail on the head.
|
|
|
|
|
|
Good People,
I have a brief question.
So I have various types of objects with a common base that I need displayed differently - obviously by their type - in a listbox. I already have built several different types of data templates for each one. The question is do I use a value converter or some other strategy.
For example, let's say I have a base Home object. Sub-classes (child objects) include HomeRanch, HomeSplitFoyer, HomeDuplex, HomeTwoFloor, HomeTwoFloorBrick (which actually inherits from HomeTwoFloor), HomeThreeStory, etc... Now, they all inherit the properties and fields of the base home class. In addition they all add a range of their own variables. (All run of the mill object-oriented design concepts.)
In my listbox I need them to each display differently depending on types. I am thinking I need to bind the list box to an ObservableCollection<object> type. However, how do I make it select the proper datatemplate depending on the specific type of object? Thanks for any ideas or help you can provide.
Blitz
|
|
|
|
|
BlitzPackage wrote: how do I make it select the proper datatemplate depending on the specific type of object?
That should happen automatically - is it not working?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark.
So, you are saying that if I just use an obeservablecollection of type "object" that it will automatically convert it to the type that the specific datatemplate needs? In other words, it will automatically know that in actuality since datatemplatehomesplitfoyer is for type HomeSplitFoyer and convert it from object to the type it needs?
I actually I haven't tried it yet. I just did not know it could do that automatically so I thought I had to implement it.
Thanks again.
Blitz
|
|
|
|
|
BlitzPackage wrote: So, you are saying that if I just use an obeservablecollection of type "object" that it will automatically convert it to the type that the specific datatemplate needs?
Yes.
I use (observable) collections of my base type instead of type "object" - less/no casting
when using the collection in code.
For each item in the collection, the available data templates (up the tree) are searched in order for a
data template with a matching DataType, so if you also have a data template for your base class,
you'll want that one last, otherwise it will be found first and applied to all derived types.
IOW, put your DataTemplate resources in order by DataType, from most derived to base.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Awesome! I can't wait to try it. That's really good. Seems Microsoft may have outdid themselves with this WPF thing.
Thanks,
Blitz
|
|
|
|
|
DataTemplates are the #1 thing I loved initially about WPF.
I used to spend (waste?) so much time doing it in MFC.
Now I let the framework do all the work
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here's a little example in case I'm not making any sense
<Window x:Class="MyNamespace.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace"
xmlns:mytypes="clr-namespace:MyTypes;assembly=MyTypes"
Title="TestWindow" Height="Auto" Width="Auto" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" >
<Window.Resources>
<local:MyBaseTypeList_design x:Key="MyBaseTypeList_design"/>
<DataTemplate DataType="{x:Type mytypes:DerivedFromMyBaseType}">
...
</DataTemplate>
<DataTemplate DataType="{x:Type mytypes:MyBaseType}">
...
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Source={StaticResource MyBaseTypeList_design}}" />
</Grid>
</Window>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, that is also awesome and really helps alot. This way, if I can't do it in blend, I can hand code it.
Blitz
|
|
|
|
|
Having the static "designer" data helps alot - then you can have
live data to see while designing the DataTemplates.
Cheers!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
What is "the static designer"? Are you talking about how Blend will populate it with some data while you are working on it?
Thanks,
Blitz
|
|
|
|
|
Heh sorry, I didn't word that right...
I meant that static resource shown in the xaml sample with the
"_design" suffix on the name. It's just a wrapper around a collection<T>
type that adds a few items to the collection in the constructor.
That way there's data available at design time (can be seen in both Blend and VS)
of the actual types I'm designing data templates for, and I can see them as they'll
look in the listbox.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi ,
I plaved a combobox and a listbox in a .xaml page. I used LINQ to fill combobox. I want the selected value to be displayed in the textbox. But i am getting object and not the exact value.I used like this,
var value=additem.selectedItem;
text1.text=value.ToString();
Pls help me!
Gomathi R
|
|
|
|
|
GomathiR wrote: text1.text=value.ToString();N/blockquote>
Because you are doing a ToString() on the object. You would need to use the objects porperty value.
e.g.
var value=additem.SelectedItem as YourObject;
text1.text = value.PropertyInYourObject;
You can do it in XAML itself also, databinding the Text property of text1. See if this works,
Text = ="{Binding ElementName=additem,Path=SelectedItem}"
|
|
|
|
|
|
Hi,
thank u very much for your help. Its working now.
Gomathi R
|
|
|
|
|