|
That looks like a good answer
I have tried to call the parent with the sender but that didn't work. That was probably because I didn't parse it as a FrameworkElement or something like that.
I wouldn't know what to do if this site and forum didn't exists. Thx very much for the help.
I will try it and let you know if it worked!
|
|
|
|
|
Ok, the sender was not the element in the canvas but the thumb. Luckely I can get the element with "this.AdornedElement" (standard build-in adorner function to get the adorned element).
So, the solution was:
private void HandleMove(object sender, DragDeltaEventArgs args)
{
FrameworkElement element = this.AdornedElement as FrameworkElement;
StanagCanvas stanagCanvas = element.Parent as StanagCanvas;
if (StanagCanvas.GetLeft(element) + args.HorizontalChange < 0)
{
StanagCanvas.SetLeft(element, 0);
}
else if (StanagCanvas.GetLeft(element) + element.Width + args.HorizontalChange > stanagCanvas.Width)
{
StanagCanvas.SetLeft(element, stanagCanvas.Width - element.Width);
}
else
{
StanagCanvas.SetLeft(element, StanagCanvas.GetLeft(element) + args.HorizontalChange);
}
if (StanagCanvas.GetTop(element) + args.VerticalChange < 0)
{
StanagCanvas.SetTop(element, 0);
}
else if (StanagCanvas.GetTop(element) + element.Height + args.VerticalChange > stanagCanvas.Height)
{
StanagCanvas.SetBottom(element, stanagCanvas.Height - element.Height);
}
else
{
StanagCanvas.SetTop(element, StanagCanvas.GetTop(element) + args.VerticalChange);
}
}
I just made it to difficult and overlooked this simple sollution! Now the element stays within the bounderies of the canvas.
thx ABitSmart
|
|
|
|
|
That's great
Looking at your code, when it crosses the bottom boundary, you are setting the Bottom. Shouldn't it be SetTop ?
|
|
|
|
|
How could I have missed that!
|
|
|
|
|
Any insight for a small civil engineering program.
It will have 4 forms(excluding open/close dialog boxes) and will run in C#:
Main - menubar, tabstrip, Datagrid and a couple buttons
Chart Form - Graphics form to display a generated flow chart
Project form - basically a glorified dialog box for project info
Report Form - basically just a .doc file holder
If I go the WPF route I would like to produce my own style (kinda like Vista but not so heavy).
I don't have much experience with WPF besides tutorials and articles and I just want some personal experiences to help me make an informed decision.
|
|
|
|
|
This is a fairly straightforward application, and shouldn't present you with too much trouble. If you adopt MVVM as your main design pattern, you'll find that it's easy to debug and test because you'll test your business logic in isolation from the way that it's presented.
You'll find it easier to code up a flow chart in WPF than you would in WinForms - so much of the graphics subsystem has been designed to make it easier to use (once you have experience). I would state though, that if you have experience in WinForms and none in WPF then you've got a steep learning curve ahead of you, and I'd get my feet wet on a couple of small applications first before tackling this one, so you might be better off using WinForms if that's what you're used to. If you don't have extensive experience in WinForms, I'd definitely recommend taking the plunge into WPF. Actually, I'd recommend it anyway, but I am a WPF nut.
"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
|
|
|
|
|
If you have swear jar in your office go with WinForms - otherwise WPF is worth a go but be prepared to climb a mountain
|
|
|
|
|
Thank for the responses. Ive been messing around with WPF and I feel its the way I'm going to go. I just don't like stepping into aging standards. WPF is is! I'm sure I'll be back with plenty of questions. Thanks.
|
|
|
|
|
I have abutton control, there are some style properties which can be set in App.xaml like this
Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="20"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
and give in button control as
Style="{StaticResource ButtonStyle}"
or in xaml.cs file as
btnTest.Style = (Style)(Application.Current.Resources["ButtonStyle"]);
But I want to generate this style dynamically and save it in a string and extract the style object from that string and apply it to the Button control.
In other words I want to take style from a string not from App.xaml.
Is it possible in Silverlight 2.0?
Thanks in advance,
|
|
|
|
|
|
I don't want to load the entire xaml file and store it.
I want this file data inside a string for example:
string s="<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="20"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="Red"/>
</Style>";
and apply that like:
btnTest.Style = (Style)(SOMETHING["ButtonStyle"]);
What will be that SOMETHING...?
How can I apply that ButtonStyle from the string s?
|
|
|
|
|
salon wrote: I don't want to load the entire xaml file and store it.
Right. I stated the article may have the info you need.
You need a Style object from the XAML. That means the XAML has to be parsed - see the article.
What are you trying to achieve that wouldn't be simpler with a few lines of code
to create a Style dynamically?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi friends
I am using sliverlight2 toolkit but it give the Error at loading time
Error:-Sys.InvalidOprationException.ManageRunTimeError error #4004 in control 'Xaml1'............................
Thanks
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Problem in Control(Combobox) just delete the Item of The comboBox.........................
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Hi,
I have a listview as below:
<br />
<Window x:Class="Practice.WPF.ListViewTest"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
Title="ListViewTest" Height="300" Width="75" Closed="Window_Closed"><br />
<br />
<ListView x:Name="listView" ScrollViewer.IsDeferredScrollingEnabled="True" VirtualizingStackPanel.IsVirtualizing="True"><br />
<ListView.View ><br />
<GridView ><br />
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path=Id}"></GridViewColumn><br />
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn><br />
<GridViewColumn Header="Price" DisplayMemberBinding="{Binding Path=Price}"></GridViewColumn><br />
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=Date}"><br />
</GridViewColumn><br />
<GridViewColumn Header="Quantity" DisplayMemberBinding="{Binding Path=Quantity}"></GridViewColumn><br />
</GridView><br />
</ListView.View><br />
</ListView><br />
</Grid><br />
</Window><br />
The problem is when there is no data bound to the listview the horizontal scrollbar disappears, and the Headers get cut off. I want the horizontal scrollbar to be still visible.
(My requirement may sound weird, but i want this functionality for a listview which displays streaming numerical data and has filters on column headers. Sometimes the filter condition does not satisfy any of the rows so the listview becomes empty and horizontal scrollbar disappears. Now some of the columns will get cut off and the user cannot scroll to that column and clear the filter.)
ANy ideas how i achieve this.
Pankaj Chamria,
Software Programmer.
|
|
|
|
|
Take a look at this Link[^]
|
|
|
|
|
Thanks for your reply.
I looked at the Link. However the solution of having two scrollbars for header and content is an overkill and quite complex [at least for a beginner like me ].
I have handled the problem by allowing the user to reset all the filters using a workaround, to get back the data and with it the scrollbars.
Pankaj Chamria,
Software Programmer.
|
|
|
|
|
Appreciate your reply. Good to know you will have happy users now
|
|
|
|
|
hi Friends
how assign theme in silverlight2?(How to work with theme in silver light2) Please Help me.
Thanks
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Install toolkit of silver light and add reference of Theme and add tag on XAML page
xmlns:shinyRed="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.ShinyBlue"
and add all the control between this tag:-
(shinyRed:ShinyBlueTheme) (/shinyRed:ShinyBlueTheme)
|
|
|
|
|
Got it working?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
ya It s working
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Hi.
Do we have a TreeView control in WPF ?
|
|
|
|
|
|
And , could we change its template ?
|
|
|
|