|
private string _value; <br />
public string Value <br />
{ <br />
get {return _value;<br />
} <br />
set <br />
{ <br />
_value = value; <br />
NotifyPropertyChanged("Value"); <br />
}<br />
Move the property code to mainpage and try....
|
|
|
|
|
But the Value property is inside of class Field , so I can't move it.
|
|
|
|
|
In order to use Value, the DataContext must be set to an instance of your Field class. That's the only way it can find it.
"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 think I am missing something in XAML, because from .cs it all works ok. Let's forget about the Field class and stick to a simpler example like binding MyValue to a TextBlock.
public String MyValue { get; set; }<br />
<br />
public MainPage()<br />
{<br />
InitializeComponent();<br />
MyValue = "test text";<br />
txtTest.DataContext = MyValue;<br />
.....<br />
<br />
<TextBlock Grid.Row="1" Name="txtTest" Text="{Binding}"/>
Above code works fine, but when i try to set DataContext in XAML it fails.
<TextBlock Grid.Row="1" DataContext={Binding MyValue} Name="txtTest" Text="{Binding}"/>
Fail
<TextBlock Grid.Row="1" Name="txtTest" Text="{Binding MyValue}"/>
Fail
Maybe I should add something to resources ?
|
|
|
|
|
ekimpl wrote: Maybe I should add something to resources ?
No. Drop the DataContext from your XAML, and then add something like this in the code behind the view:
private Field _field;
private void SetContext()
{
_field = new Field();
DataContext = Field;
} Then call this method from immediately after the call to InitializeComponent();
"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
|
|
|
|
|
Pete O'Hanlon wrote: No. Drop the DataContext from your XAML
He could alsways set the datacontext via the xaml.
However, here this solution is perfect.
|
|
|
|
|
Pete, I could use Your solution, but as I wrote, there is no problem when setting DataContext form .cs. I just wanted to find the reason why I could not bind my Properties in XAML.
And I found the reason, with Your (both Pete and Abhinav) clues. It was because my declaration of DataContext for LayoutRoot was wrong. I moved it from XAML to .cs
LayoutRoot.DataContext = this;
so now it points to my MainPage class, and now, I can bind local properties with no need to set the context for each control in XAML
public Field Val { get; set; }
<TextBlock Grid.Row="1" Name="txtTest" Text="{Binding Val.Value}"/>
So, thanks for Your help guys, I think the problem is solved.
|
|
|
|
|
ekimpl wrote: So, thanks for Your help guys
You are welcome.
|
|
|
|
|
Hi Experts,
I have a user control. I am dynamically adding controls to this user control using Children.Add . I want to change their location on some event in code. Like we can do in winform using Location. Is there anything similar to this?
Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
You could always set the Margin of the control to move/size it. Without knowing what exactly you are trying to achieve, it's hard to add any more detail.
"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 think i was a little too generic in explaining my problem. I will give my current scenario.
I am trying to build an MDI in WPF. As you know there is no concept of MDI in WPF but i got a simulated MDI code from codeplex. The link for the same is given here. Now i want to tile the child controls in the mdi either horizontally, vertically or cascade in the way similar to windows MDI like this.LayoutMdi(MdiLayout.TileHorizontal); .
Please help!
Thanks in advance.
Regards,
Samar
|
|
|
|
|
Did you mean something like this?
[code]
<Canvas>
<Rectangle Width="50" Height="50" Fill="Red"
Canvas.Left="50" Canvas.Top="50">
</Rectangle>
</Canvas>[/code]
Try to copy and paste this in a blanc scene, it that what you want then you can also do this in code behind
[code]Rectangle rect = new Rectangle {
Width = 50,
Height = 50,
Fill = new SolidColorBrush(Colors.Blue) };
Canvas.SetLeft(rect, 50);
Canvas.SetTop(rect,50); [/code]
|
|
|
|
|
Yeah something on the similar lines. I got the solution as.
uc1.SetValue(Canvas.TopProperty, Convert.ToDouble(12));
uc1.SetValue(Canvas.LeftProperty, Convert.ToDouble(12));
The above will move the usercontrol uc1 12 from the top and 12 from the left. Thanks.
Regards,
Samar
|
|
|
|
|
Hi, I've been playing around with the code found at this website: http://dvuyka.spaces.live.com/blog/cns!305B02907E9BE19A!171.entry
It uses thumbs for dragging and LineGeometries for drawing connections between them. I was wondering if and how one would go about removing these at runtime, such as by right-clicking on them.
Thanks!
|
|
|
|
|
Find the link item that you want in the child collection and remove it.
connectors.Children.Remove(link);
"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
|
|
|
|
|
Well i figured out that part, but my question is more of how to find the link item in the child connection from a mouse click. Is that possible?
|
|
|
|
|
Without going through the code in depth, I'd imagine that the Link object would have an IsSelected property available on it - it should be a simple enough. If it doesn't, you'll need to perform a hit test (typically in the OnMouseLeftButtonDown event handler:
Point pt = e.GetPosition((UIElement)sender);
HitTestResult result = VisualTreeHelper.HitTest(canvas, pt);
if (result != null)
{
LineGeometry line = result.VisualHit as LineGeometry;
}
"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 keep getting result as null when i click on the LineGeometry/Path
|
|
|
|
|
Hi all,
i have a issue in focusing the datagrid in WPF.
Its a data entry form in which,
the datagrid will be filled w.r. to a text box.
that is i am having one text box, upon entering some values in the text box and after clicking the tab(lost focus) the data grid will get filled.
i have given the tab index as
Text box -1
datagrid - 2
button - 3.
But now when i press tab from the text box the tab focus is going to button and not the datagrid.
the focus is coming to the datagrid after completion tab's of all tab enabled control in my form.
Any idea to fix this issue?
thanks in advacne
|
|
|
|
|
I am new to silver light ..i am using IIS 5.1 and silver light 3.0 . How to deploy ...please help!
|
|
|
|
|
There are quite a few articles on this topic available on the internet.
See here for starters.
|
|
|
|
|
You're going to have to implement it yourself and then come back here if you have problems. The topic is WAY too broad to provide a "one-size-fits-all" answer.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
i have done all the Rnds. but still getting following error
"Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid".. Please help!
|
|
|
|
|
Hi Experts,
Unlike in windows forms, wpf's toolbar does not have an "ItemClicked" event associated with it where i can have just 1 event for the clicks of all the items (buttons) present in the toolbar. I can very well create an event for each and every button but i want to reduce the mess that the individual event would create in code. Is there a work around to achieve this functionality?
Thanks in advance.
Regards,
Samar
|
|
|
|
|
Hi all,
I have a quantity attribute in a dataform and want to validate it.I also have two methods for validate it. Their name are : ValidateUnit and ValidateQuantity.
But unfortunally i could only call one method for validate it by following below code :
[CustomValidation(typeof(UnitValidation), "ValidateUnit")]
public string Unit;
.......
How could i call two methods for validating Unit ?
|
|
|
|