|
Maybe this can help -
Goto the web project of your SL solution, right click on it and view the project properties.
Goto the Web option and ensure the Silverlight debugger is checked.
|
|
|
|
|
Hi, this thing is killing me..
I have object drag of type Field and I would like to bind it to a productsDataGrid 's property Drag in XAML. In codebehind it all works well :
public class Field : INotifyPropertyChanged
{
...
public string Value
...
}
public partial class MainPage : UserControl
{
public Field drag;
public MainPage()
{
drag = new Field();
drag.Value = "true";
productsDataGrid.Drag = drag;
but in XAML it's not.
<cont:DragGrid Name="productsDataGrid" Drag="{Binding drag, Path=Value}"/>
How to set this binding correct ?
|
|
|
|
|
Make Value a property, not a field.
"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, sorry I didn't paste complete code of Field class, but Value is already a property
public class Field : INotifyPropertyChanged
{
private string _value;
public string Value
{
get {return _value;}
set
{
_value = value;
NotifyPropertyChanged("Value");
}
Edit: I deleted my last message, because I thought I worked the solution, so the question is still unanswered.
modified on Saturday, June 26, 2010 9:50 AM
|
|
|
|
|
ekimpl wrote: <cont:draggrid name="productsDataGrid" drag="{Binding drag, Path=Value}">
I did not see you setting the Datacontext for the xaml anywhere.
What is it set to?
|
|
|
|
|
I set DataContext in LayoutRoot
<UserControl x:Class="MFP.MainPage" ..... >
<UserControl.Resources>
<my:MainPage x:Key="mainpage"/>
</UserControl.Resources>
<Canvas x:Name="LayoutRoot" DataContext="mainpage" ...
|
|
|
|
|
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
|
|
|
|