wpf binding text - wpf

WPF C# VS2008 3.5 I have a few pages(page1.xaml ect.) and I would like to bind text from a textbox to a label on a different page in xaml. I tried using ElementName but the label does not show the text user enters in textbox. I know something is wrong in the Path, but I'm new to wpf so any help would be great. My xaml referenced the x:Name of the textbox, should I reference the page also? thanks in advance

I think it would be better to create a class that will hold the data and create a single object of that class and bind both pages to it.

Related

Can a UserControl be saved as XAML at runtime in WPF?

I have a UserControl that includes Labels, TextBox and Charts (generic types). After the user loads this control in a grid at runtime, can it be saved as XAML? So a later user can load his file and edit it. If the UserControl cannot be saved as XAML what is the other way to save it?
Thanks for any inputs,
I think you will want to look at the XamlWriter / XamlReader Classes. There are some limitations but they might work for you.

Labeled text box

i am trying to write a control template where i want a label for text box on top of the textbox. So i invite your suggestions for how to achieve this.
so far i did that using a stack pannel with vertical orientation and then added textblock and text box. Like wise i created 45 stackpannels. So i dont want to go like that. instaed i want to write a control template where i can have label and text box and then set label value and text box value.
my:CustomControl labelText="First Name:" TextBoxText="john Doe" />
any ideas are greatly appreciated.
Thanks.
You can make a UserControl with DependencyProperties for Text and Label, put your StackPanel in it, and bind the label and textbox to the dependency properties.
Make sure the Text property has FrameworkPropertyMetadata.BindsTwoWayByDefault
Have a look at the Silverlight Toolkit
It includes both HeaderedContentControl and DataField controls. The DataField is mainly for use with DataForm, but as far as I know, you can use it any way you like. The HeaderedContentControl I haven't tried myself, but it could be just what you are looking for.

What is the best approach to load xaml directly?

I have xaml directly stored in database. Mostly they contain hyperlinks and textblocks. How do i load this in xaml such that the controls are instantiated and seen properly. If i bind it directly to textblock the text will be seen as it is (i.e the xaml won't get instantiated). One approach is to use richtextbox and it would work fine. However, i want a label type of control and not a textbox.
Thanks in advance :)
A good approach here is to use XamlReader.Load() (Silverlight) or XamlReader.Parse() (WPF) which parses a string and returns an element corresponding to the root of the XAML document.
XamlReader.Load Method (String)
XamlReader.Parse Method (String)

WPF "flying" combobox

is it possible to create a combobox in wpf from code, which I could position wherever I want on the window?
In my case, I basically want to create something like a Autocomplete for DataGrid rows,...
Thanks!
TextBox supports auto complete, and you can create your datagrid's template column and you can specify the template with textbox which can interact and give you autocompletion.
if you put it in a <Popup> you can then position the popup wherever you want--it is not "bound" by a parent container.

Silverlight: How to style the validation tooltip?

I did some searching but it wasn't what I was looking for. So, does anyone know a way how to style the validation tooltip in Silverlight(the thing in the green border)?
alt text http://img689.imageshack.us/img689/222/validationtooltip.png
Any help would be greatly appreciated!
Best Regards,
~K
Unfortunately you can't easily provide a style for the validation tooltip without effectively styling the entire Textbox control. Blend makes this fairly easy if you are familiar with using that design tool. However if your a dyed in the wool coder like me then...
Goto this page on MSDN TextBox Styles and Templates
Copy the vsm namespace alias to your UserControl xaml
Copy the TextBox style into UserControls.Resources give it at an x:Key name (say MyTextBoxStyle")
Copy the ValidationToolTipTemplate from the web page to the UserControls.Resources, paste it above the TextBox style. It already has an x:Key name that the TextBox style will be referencing.
Add Style="{StaticResource MyTextBoxStyle}" to your TextBox in the data grid.
Now you play around with the validation elements of the templates to get your desired result.
The validation messages are displayed as a visual state. you can get to these (and edit them) as templates directly from blend.

Resources