|
Sorry - that should have been myControl instead of p ...
.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
|
|
|
|
|
Hi all. I've been gathering little bits of code from here, there and everywhere. I've got it doing what I want for the most part and just need someone's advice on the last part.
I have a button that moves it's position randomly when you trigger the Mouse Enter event. This works, but I want it to only move if the proposed position will be within the bounds of the control's form. Here's my code:
private void MoveControl(Control control, Window form)
{
TransformGroup tGroup = new TransformGroup();
tGroup.Children.Add(new TranslateTransform(50.0, 50.0));
control.RenderTransform = tGroup;
DoubleAnimation dA_X = GenerateDoubleAnimation(-50, 50);
DoubleAnimation dA_Y = GenerateDoubleAnimation(-50, 50);
TranslateTransform tt = (control.RenderTransform as TransformGroup).Children[0] as TranslateTransform;
double dTop = Canvas.GetTop(control) + (double)dA_X.To;
double dLeft = Canvas.GetLeft(control) + (double)dA_Y.To;
double dBottom = dTop + control.Height+ (double)dA_X.To;
double dRight = dLeft+control.Width + (double)dA_Y.To;
if (dTop > 0 && dLeft > 0 && dBottom < form.Height && dRight < form.Width)
{
tt.BeginAnimation(TranslateTransform.XProperty, dA_X);
tt.BeginAnimation(TranslateTransform.YProperty, dA_Y);
GeneralTransform myTrans = control.TransformToAncestor(this);
Point p1 = myTrans.Transform(new Point(0, 0));
control.SetValue(Canvas.LeftProperty, p1.X + dA_X.To);
control.SetValue(Canvas.TopProperty, p1.Y + dA_Y.To);
}
else
{
MoveControl(control, form);
}
}
DoubleAnimation GenerateDoubleAnimation(int min,int max)
{
DoubleAnimation da = new DoubleAnimation();
da.To = randomNumber.Next(min, max);
da.Duration = new Duration(TimeSpan.FromSeconds(.2));
return da;
}
I was hoping that this would prevent it moving outside of the form, but it doesn't. Also, I get an error with this line sometimes:
tGroup.Children.Add(new TranslateTransform(50.0, 50.0));
StackOverFlow error, that I don't understand.
Any pointers and help will be gratefully received.
Jib
modified on Friday, September 17, 2010 6:11 AM
|
|
|
|
|
I have added a handler for MouseRightButtonDown to a canvas inside a usercontrol but it never gets fired or if it does get fired it drifts off in the ether. Is there a way of finding out why this happens?
|
|
|
|
|
|
You might also want to take a look at Crack.NET[^]. It's a complementary product to snoop.
|
|
|
|
|
Cheers - I remember reading about it a year or so ago but didn't have any requirement for it at the time - I think its time has come. Thanks for reminding me.
|
|
|
|
|
You're welcome mate. Glad to help.
|
|
|
|
|
Hi all,
I'm working with MS Ribbon Control Library in VS2010 (using WPF and MVVM) and what to recreate something that Word 2010 does... (I'm not sure what MS call this function)
If you open a new doc in Word 2010, you get the document in a view window (as normal). However, if you then select File, it will open a new window / workspace with Information about Document1 for this tab... Select Home tab and it goes back to the view of the document.
1: What does MS call this function>
2: How do I create a new window / workspace for each tab.
I have tried the following snippet:
<r:RibbonTab Header="Home" >
<r:RibbonGroup Header="Imaging">
<r:RibbonButton Label="Archive Images" />
<r:RibbonButton Label="Our Images" />
</r:RibbonGroup>
<r:RibbonTab.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter /> <!-- Show only contentcontrol HomePage -->
</Trigger>
</r:RibbonTab.Triggers>
</r:RibbonTab>
...
<ContentControl x:Name="HomePage" Visibility="Collapsed"/>
<ContentControl x:Name="DocPage" Visibility="Collapsed"/>
But I'm stuck!!
Love & Light
|
|
|
|
|
I've also tried:
<r:RibbonTab.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="True" >
<!--<Setter TargetName="HomePage" Property="ContentControl.Visibility" Value="Visible" />-->
</DataTrigger>
</r:RibbonTab.Triggers>
But get the error message
XamlParseException occurred
'Initialization of 'Microsoft.Windows.Controls.Ribbon.RibbonTab' threw an exception.' Line number '65' and line position '18'.
Love & Light
|
|
|
|
|
I have a couple of events used to display the currently selected record.
private void GridLoaded(object sender, RoutedEventArgs e)
{
(sender as DataGrid).SelectionChanged += new SelectionChangedEventHandler(GridSelectionChanged);
}
private void GridSelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid oDG = sender as DataGrid;
int Index = oDG.SelectedIndex;
if (Index >= 0 )
{
oDG.ScrollIntoView(oDG.SelectedItem, oDG.Columns[0]);
}
}
This needs to be applied to every grid in the application. I want to move these events to a helper class and bimd from the xaml to the helper class.
currenct binding is:
Loaded="GridLoaded"
Any suggestions on the correct syntax for binding to a helper event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Collin Jasnoch wrote: "{Binding Path=MyHelper.GridLoaded}"
That looks more like what I'm looking for, thanks
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi, I'm developing my first application in WPF and I got stuck on this.
I have one Solution with several projects. I have a project for the main window, one for the menus, and another for the controls. The logic is that the main window will have one (or several) menu, and the menu has, again, one or several customized controls. The reason I did this is because I'll be needing to re-use the same controls and menus on a different configuration for the next project.
Now for my question... let's say that my projects are called "Controls", "Menus" and "Main". I have a customized button(user control) and a customized canvas(user control) in "Controls". Now, everything goes to the main window in "Main", the button goes inside the menu from "Menus" wich in turn goes to the main window, and the canvas goes directly to the main window grid.
My struggle is how to raise an event from the button once is clicked and that in the canvas a control(let's say a text box) appear at a location designated either by me or the user.
Is there a way to do this? I've tried with dependency properties but with complete failure. I'd appreciate for any kind of help.
Thanks
|
|
|
|
|
Not sure where the coordinates will come from, but let's assume it will be a dependency property on your custom button. You can then programmatically bind to that property from your menu. There will be a dependency property on your menu that the binding is set to update. You can then bind to that property from the textbox so that the canvas coordinates get updated. You can also update the visibility of the textbox using an IValueConverter that converts a bool (another dependency property linked between the button and menu) to a visibility value.
Not sure I understood your question correctly, but hopefully those ideas will help you get a start.
|
|
|
|
|
Hi , I am getting below error when try to run the VS2003 application.
---------------------------
Microsoft Development Environment
---------------------------
Error while trying to run project: Unable to start debugging on the web server. Server side-error occurred on sending debug HTTP request.
Make sure the server is operating correctly. Verify there are no syntax errors in web.config by doing a Debug.Start Without Debugging. You may also want to refer to the ASP.NET and ATL Server debugging topic in the online documentation.
---------------------------
OK Help
---------------------------
- Ajay K
|
|
|
|
|
Well, as WPF/Silverlight don't run in VS2003, how is this related to this forum?
|
|
|
|
|
You need Visual Studio 2005 (at least) for WPF and Visual Studio 2008 for Silverlight.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Hello,
Whenever I try getting the size of a custom control (inside the code), both ActualWidth/Height and DesiredSize returns either Size(0, 0) or Size(Width, Double.NaN) or Size(Width, Double.PositiveInfinity). Same with Height/Width.
Any suggestions?
Thanks,
Theo
|
|
|
|
|
Hi Theo,
Are you trying to get the size of the control from inside the control. I mean inside control's
ArrangeOverride or do you want to get the control's size in application level?
|
|
|
|
|
I'm struggling to identify the correct way to move from one control to another using MVVM. I have implemented the navigation framework and MVVMLight. UserVM is the viewmodel and it is a static property the ViewModelLocator
public static UserDetailsVM UserDetailsVMStatic
{
get
{
if (_UserDetailsVM == null)
{
CreateUserDetailsVM();
}
return _UserDetailsVM;
}
}
So I have a control with a list of users in a datagrid, the user clicks on the hyperlinkbutton and navigates to the details form. The ID is correctly passed via the navigation but I'm not using it yet as I expect to use the existing VM.
The details control binds to the static VM and should show the selected user details from the datagid control (this works within the same page).
This control binding does not return the selected user details but the FIRST users details.
DataContext="{Binding UserDetailsVMStatic, Source={StaticResource Locator}}"
The textbox binding should show the user details of the selected user from the list page
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding EditableUserDetails.Email, Mode=TwoWay}"/>
Except I already have a VM created to service the datagrid control and it has the selected item in a property.
How can I use the existing VM in the details form.
Do I have to chase through the staticresource dictionary to get the VM from the locator or is there a way to do this in XAML.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
So the question turned out to be wrong.
What I wanted to do was use the same viewmodel to service the 2 views. This was achieved by binding both views to the STATIC viewmodel in the viewmodellocator.
This can be done either code behind or xaml
public NTFXPastCash()
{
InitializeComponent();
this.Layoutroot.DataContext = ViewModels.ViewModelLocator.NTFXPastCashVMStatic;
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello.
I create a UseControl and i'd like to add an collection DependencyProperty.
<br />
......<br />
private static DependencyPropertyKey ItemsPropertyKey = <br />
DependencyProperty.RegisterReadOnly("MyItems",<br />
typeof(List<TextBlock>), typeof(AutoCompleteTextBox),<br />
new FrameworkPropertyMetadata(new List<TextBlock>(), MyListChanged)<br />
);<br />
<br />
static void MyListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)<br />
{<br />
}<br />
<br />
public List<TextBlock> MyItems<br />
{<br />
get { return (List<TextBlock>)GetValue(FileNameProperty); }<br />
set { SetValue(FileNameProperty, value); }<br />
}<br />
.........<br />
How can I do the same with a collection of string and not of TextBlock?
thanks
|
|
|
|
|
What is the problem with List<string> ?
AFAIK, You can create a DependencyProperty of any type. Just change the Type of List<textblock> to List<string>
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
The problem is that when I set the dependencyProperty on XAML I do something like:
<br />
<MyControlsNameSpace:MyControl.MyItems> <br><br />
<TextBlock Text="First Item" /> <br><br />
<TextBlock Text="Second Item" /> <br><br />
</MyControlsNameSpace:MyControl.MyItems><br />
But if I have a List of string I don't know How to set this property
Thanks
|
|
|
|
|
Well my friend, why don't you use ItemsControl in this regard.
You can go for ListBox.
<ListBox ItemsSource="{Binding}" DataContext="{StaticResource MyItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MyProperty}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If you are using List of STRING you dont need to specify property name. Use Text="{Binding}" which will eventually call ToString for the string object and get the value of it.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
Hello
I'm not so good in wpf.
If I understand well you say that I have to change my property type to ItemsControl intead of String and add a ListBox with that XAML on my custom control.
Is it correct?
|
|
|
|