I'm working on wpf application , the application draws the countours on an existing image and i want to add a button which give me the hand to zoom the image to see the countours
i added a button and a fonction on .cs but it doesn't work
here's the code cs
namespace AnimationTest
{
public partial class MainWindow: Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 1000;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
image1.BeginAnimation(ScaleTransform.CenterXProperty, da);
}
}
}
and XAML Code
<Window x:Class="AnimationTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="720" Width="1280">
<Grid>
<Image Height="681" HorizontalAlignment="Left" Name="image1" Stretch="None" VerticalAlignment="Top" Width="1258" Source="/AnimationTest;component/Images/world.jpg" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="1171,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
what's the problem ? and how can i fixe it ?
thanks
This has no sens image1.BeginAnimation(ScaleTransform.CenterXProperty, da); You start an animation on an image of a property that don't belong to Image control. You should create a scale transform, set it on the image and then start the animation on scale transform object, not the image.
Related
Im sure this is a super easy one but I am working on a C# UWP app and am trying to make a drag-able user control but in my mouse event I'm getting the following error:
CS1061 'MouseEventArgs' does not contain a definition for 'GetPosition' and no extension method 'GetPosition' accepting a first argument of type 'MouseEventArgs' could be found (are you missing a using directive or an assembly reference?)
I found this example I am using on stack (Dragging a WPF user control) and have used mouse down events before for dragging items between list boxes in winforms but didn't have this issue.
Here is my code:
<UserControl
x:Class="HopHaus.TimerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HopHaus"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400" Width="120" Height="60">
<Grid Margin="0,0,0,167" Width="120">
<Rectangle Fill="#FF404040" HorizontalAlignment="Left" Height="60" Margin="1,0,-1,-133" Stroke="Black" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="timersetBox" Margin="-1,-2,1,-59" TextWrapping="Wrap" Text="00" VerticalAlignment="Top" Height="60" BorderBrush="Transparent" FontFamily="Fonts/DIGITAL.TTF#Digital" Foreground="#FF72FB00" FontSize="50" Background="Transparent" TextAlignment="Right" AcceptsReturn="True" SelectionHighlightColor="#000078D7" Width="120"/>
<Border x:Name="dragBrdr" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="59" Margin="2,0,0,-59" VerticalAlignment="Top" Width="118"/>
</Grid>
</UserControl>
And:
public sealed partial class TimerControl : UserControl
{
Point currentPoint;
Point anchorPoint;
bool isInDrag;
public TimerControl()
{
this.InitializeComponent();
}
private TranslateTransform transform = new TranslateTransform();
private void root_MouseMove(object sender, MouseEventArgs e)
{
if (isInDrag)
{
var element = sender as FrameworkElement;
currentPoint = e.GetPosition(null);
transform.X += currentPoint.X - anchorPoint.X;
transform.Y += (currentPoint.Y - anchorPoint.Y);
this.RenderTransform = transform;
anchorPoint = currentPoint;
}
}
}
I am using both using System.Windows.Input & using Windows.Devices.Input
Thanks a bunch in advance for any help provide.
To have better support for touch and inking there is an abstraction over the mouse events. This is called pointer. So in you you have a PointerMoved event
in xaml:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
PointerMoved="Grid_PointerMoved">
</Grid>
and in code
private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(null);
}
but am still unsure how to take my var point and transform it into a new position of my user control on my MainPage
As #Dave Smits said you need a Pointer event handle. More details about handle pointer input please reference this document. I think what you confused is that this code var point = e.GetCurrentPoint(null); return PointerPoint object instead Point structure what you needed for transform. In that case, you can get the Point structure by PointerPoint.Position property. Updated code as follows:
<UserControl
...
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
Width="120" Height="60" PointerMoved="Grid_PointerMoved" CanDrag="True">
<Grid Margin="0,0,0,167" Width="120" >
<Rectangle Fill="#FF404040" HorizontalAlignment="Left" Height="60" Margin="1,0,-1,-133" Stroke="Black" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="timersetBox" Margin="-1,-2,1,-59" TextWrapping="Wrap" Text="00" VerticalAlignment="Top" Height="60" BorderBrush="Transparent" FontFamily="Fonts/DIGITAL.TTF#Digital" Foreground="#FF72FB00" FontSize="50" Background="Transparent" TextAlignment="Right" AcceptsReturn="True" SelectionHighlightColor="#000078D7" Width="120"/>
<Border x:Name="dragBrdr" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="59" Margin="2,0,0,-59" VerticalAlignment="Top" Width="118"/>
</Grid>
</UserControl>
Code behind
Point currentPoint;
Point anchorPoint;
bool isInDrag;
private TranslateTransform transform = new TranslateTransform();
private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
anchorPoint = new Point(300, 200);
isInDrag = true;
if (isInDrag)
{
var element = sender as FrameworkElement;
PointerPoint currentPointpointer = e.GetCurrentPoint(null);
currentPoint = currentPointpointer.Position;
transform.X += currentPoint.X - anchorPoint.X;
transform.Y += (currentPoint.Y - anchorPoint.Y);
this.RenderTransform = transform;
anchorPoint = currentPoint;
}
}
Additionally, for transform from one point to another I recommend you to use PointAnimation.
I want to make the window have the effect can change the whole window which has many elements evenly to white, as the window behind in the picture:
I use code like
public MainWindow()
{
this.Opacity = 0.5;
}
but it change to black
How to make it whole evenly change to white even when there're many Element in the Window and don't set the window Style to none?(Because set Window AllowTransparent seems have to set the Style to none at the same time)
I hope can using code to do it, because I want to do it dynamically.
(Or possibly it use UserControl but not Window to achieve this effect? maybe the UserControl use with the Window and set the UserControl to Transparent can do it
----After I try, I find UserControl doesn't have property AllowTransparent, so it seems imposible use this way )
Basically, you have two options:
Use white Background color on Window and change Opacity on the window children, so the white starts to shine through
<Window Background="White">
<Grid Opacity="{Binding WhiteOutVisibility}" Background="WhiteSmoke">
<YourContent/>
</Grid>
</Window>
Use a white overlay control with alpha or Opacity that lets the actual content shine through
<Grid>
<YourContent/>
<Border Background="#80ffffff" Visibility="{Binding WhiteOutVisibility}"/>
</Grid>
In my opinion, you should use a white overlay if you want to block user interaction with the window content and white background if you want to continue user interaction.
If you need to fade only the client area, you can just put overlay - some empty semitransparent control over all the content on the window.
You can achieve this effect by laying a canvas over your window, and setting the background to white and an opacity value. Some xaml like this will work. Just change the UserControl for Window.
<UserControl x:Class="View.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="100">
<Grid>
<TextBox Text="Hello there" />
<!-- this will show faintly -->
<Canvas Background="White" Opacity="0.8"></Canvas>
</Grid>
</UserControl>
This xaml looks like this:
The Window type has property AllowsTransparency. You can find it property on your window properties in MSVisualStudio. This can solve your problem.
Thanks for Phillip Ngan and grek40 s' answer,
both Grid and Canvas with background white and opacity works,
I write some test code that can show the effect
Xaml Part
<Window x:Class="WPFAbitraryTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0" Background="Blue" Foreground="White" FontSize="20" Click="SwitchOpacity_OnClick">Clcik to SwitchOpacity</Button>
<Button Grid.Row="1" Background="ForestGreen">hi2</Button>
<ListBox Grid.Row="2" Background="Orange">
<ListBoxItem>ListBox Item #1</ListBoxItem>
<ListBoxItem>ListBox Item #2</ListBoxItem>
<ListBoxItem>ListBox Item #3</ListBoxItem>
</ListBox>
<!-- <Grid Grid.Row="1" Grid.RowSpan="2" Opacity="0.9" Background="WhiteSmoke"/> -->
<Canvas Name="WhiteMaskCanvas" Grid.Row="1" Grid.RowSpan="2" Background="White" Opacity="0.5"></Canvas>
</Grid>
</Window>
.
Class Part
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void SwitchOpacity_OnClick(object sender, RoutedEventArgs e)
{
int opacityVal = 0;
Task.Factory.StartNew(() =>
{
for (int i = 0; i <= 1000; i++)
{
int j = 0;
Thread.Sleep(100);
//Use ++ % to change Opacity
this.Dispatcher.Invoke(
DispatcherPriority.SystemIdle,
new Action(() =>
{
WhiteMaskCanvas.Opacity = ++opacityVal % 10 / 10.0;
}));
////Use Abs Cosine to Change Opacity
//this.Dispatcher.Invoke(
// DispatcherPriority.SystemIdle,
// new Action(() =>
// {
// WhiteMaskCanvas.Opacity =
// Math.Abs(Math.Sin(++opacityVal*0.1)) ;
// }));
}
});
}
}
.
The Result:
.
further code,
if want to make the canvas mask whole window, you can change the canvas to
<Canvas Name="WhiteMaskCanvas" Grid.Row="0" Grid.RowSpan="3" Background="White" Opacity="0.5"></Canvas>
and add code to class:
public MainWindow()
{
InitializeComponent();
WhiteMaskCanvas.Visibility = Visibility.Collapsed;
}
private void SwitchOpacity_OnClick(object sender, RoutedEventArgs e)
{
WhiteMaskCanvas.Visibility = Visibility.Visible;
int opacityVal = 0;
Task.Factory.StartNew(() =>
{
//below same as code above
how can move (change position) label from position to another using wpf **
animation
** in specify event such click using c# code not trigger ??
using System.windows.media.animation;
XAML
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Canvas>
<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Button_Click" Canvas.Left="201" Canvas.Top="116" x:Name="Button"/>
</Canvas>
</Window>
Code
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var storyboard = new Storyboard();
var pointAnimation = new DoubleAnimation()
{
From = Canvas.GetLeft(Button),
To = Canvas.GetLeft(Button) + 200,
Duration = new Duration(TimeSpan.FromSeconds(10))
};
Storyboard.SetTarget(pointAnimation, Button);
Storyboard.SetTargetProperty(pointAnimation, new PropertyPath(Canvas.LeftProperty));
storyboard.Children.Add(pointAnimation);
storyboard.Begin();
}
I am attempting to create a program in which the User can create multiple profiles. These profiles can be accessed via buttons that appear as each profile is completed.
My problem:
I have no clue how to make the created buttons persist after the program is exited(I need to save the buttons?)
Visually, this is program's process: 1) Enter your information, click continue 2) View a display page of what you entered, click done. 3) This adds a button to the final window, the button of course takes you to 4) Your profile you just created.
After this, the program ends and nothing is saved. I'm fairly new to c# and am quite confused on how to "save" multiple buttons without massively complicating the code. I'm a complete noob to c# and have a little Java experience. Am I going about this correctly? I'm pretty sure its possible but have no idea to go about it.
I will include my code below. I'm working in visual studios 2012. any help would be appreciated!
MainWindow XAML:
<Window x:Class="VendorMain.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Label Content="FirstName" HorizontalAlignment="Left" Margin="63,45,0,0" VerticalAlignment="Top"/>
<Label Content="LastName" HorizontalAlignment="Left" Margin="63,71,0,0" VerticalAlignment="Top"/>
<Label Content="Image" HorizontalAlignment="Left" Margin="63,102,0,0" VerticalAlignment="Top"/>
<Image Name="imgPhoto" Stretch="Fill" Margin="63,133,303,69"></Image>
<Button Name="UploadImageButton" Content="Upload Image" HorizontalAlignment="Left" Margin="130,105,0,0" VerticalAlignment="Top" Width="84" Click="UploadImageButton_Click"/>
<TextBox Name="AssignFirstName" Text="{Binding SettingFirstname}" HorizontalAlignment="Left" Height="23" Margin="130,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" />
<TextBox Name="AssignLastName" Text="{Binding SettingLastName}" HorizontalAlignment="Left" Height="23" Margin="130,75,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button Name="ContinueToDisplayWindow" Content="Continue" HorizontalAlignment="Left" Margin="409,288,0,0" VerticalAlignment="Top" Width="75" Click="ContinueToDisplayWindow_Click" />
</Grid>
MainWindow Code:
namespace VendorMain
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void UploadImageButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Select a picture";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
imgPhoto.Source = new BitmapImage(new System.Uri(op.FileName));
//SettingImage.Source = imgPhoto.Source;
}
}
private void ContinueToDisplayWindow_Click(object sender, RoutedEventArgs e)
{
DisplayPage displaypg = new DisplayPage();
displaypg.DpFirstName.Content = AssignFirstName.Text;
displaypg.DpLastName.Content = AssignLastName.Text;
displaypg.DpImage.Source = imgPhoto.Source;
displaypg.Show();
}
}
}
DisplayPage XAML:
<Window x:Class="VendorMain.DisplayPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DisplayPage" Height="300" Width="525">
<Grid>
<Label Name="DpFirstName" Content="{Binding getFirstNamePermenent}" HorizontalAlignment="Left" Margin="86,55,0,0" VerticalAlignment="Top"/>
<Label Name="DpLastName" Content="{Binding getLastNamePermenent}" HorizontalAlignment="Left" Margin="87,80,0,0" VerticalAlignment="Top"/>
<Image Name="DpImage" HorizontalAlignment="Left" Height="100" Margin="94,111,0,0" VerticalAlignment="Top" Width="100"/>
<Button Name="ButtonizeThisProfile_Button" Content="Done" HorizontalAlignment="Left" Margin="420,238,0,0" VerticalAlignment="Top" Width="75" Click="ButtonizeThisProfile_Button_Click"/>
</Grid>
DisplayPage Code:
namespace VendorMain
{
/// <summary>
/// Interaction logic for DisplayPage.xaml
/// </summary>
public partial class DisplayPage : Window
{
public Button bot1;
public DisplayPage()
{
InitializeComponent();
}
private void newBtn_Click(object sender, RoutedEventArgs e)
{
carryToFinalView();
}
private void ButtonizeThisProfile_Button_Click(object sender, RoutedEventArgs e)
{
UserProfiles uPro = new UserProfiles();
System.Windows.Controls.Button newBtn = new Button();
newBtn.Content = "Person1";
newBtn.Name = "NewProfileButtonAccess";
newBtn.Click += new RoutedEventHandler(newBtn_Click);
uPro.ButtonArea.Children.Add(newBtn);
uPro.Show();
}
public void carryToFinalView()
{
DisplayPage displaypg = new DisplayPage();
displaypg.DpFirstName.Content = DpFirstName.Content;
displaypg.DpLastName.Content = DpLastName.Content;
displaypg.DpImage.Source = DpImage.Source;
displaypg.Show();
}
}
}
UserProfile XAML:
<Window x:Class="VendorMain.UserProfiles"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="UserProfiles" Height="300" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".8*" />
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="11*"/>
</Grid.RowDefinitions>
<Label Content="User Profiles: " HorizontalAlignment="Left" Margin="37,47,0,0" VerticalAlignment="Top"/>
<StackPanel Name="ButtonArea" Grid.Column="2" Grid.Row="2">
</StackPanel>
<Button Name="AddAnotherProfileButton" Content="Button" HorizontalAlignment="Left" Margin="35,146,0,0" Grid.Row="1" VerticalAlignment="Top" Width="75" Click="AddAnotherProfileButton_Click"/>
</Grid>
UserProfile Code:
namespace VendorMain
{
public partial class UserProfiles : Window
{
public UserProfiles()
{
InitializeComponent();
}
private void AddAnotherProfileButton_Click(object sender, RoutedEventArgs e)
{
MainWindow mw = new MainWindow();
mw.Show();
}
}
}
As a self proclaimed 'noob', I fear that you won't receive an answer here. I certainly don't have time to repeatedly come back to answer a whole continuing stream of related questions. I also don't have time to provide you with a complete solution. However, I am happy to provide you with sort of 'pseudo code' to at least point you in the right direction... you will have to do a lot of this yourself.
So first things first, as mentioned in a comment, although it is possible, we don't generally save the UI Button objects, but instead we save the data that relates to the user profiles. Therefore, if you haven't done this already, create a User class that has all of the relevant properties. Implement the INotifyPropertyChanged Interface in it and add the SerializableAttribute to the class definition... this will enable you to save this class type as binary data.
Next, in your UI, don't add each Button in xaml... there's a better way. One way or another, add a collection property of type User or whatever your class is called, and set this as the ItemsSource of a ListBox. The idea here is to add a DataTemplate for your User type which will display each of the User items in the collection as a Button:
<DataTemplate x:Key="UserButtonTemplate" DataType="{x:Type DataTypes:User}">
<Button Text="{Binding Name}" Width="75" Click="AddAnotherProfileButton_Click" />
</DataTemplate>
You can find out more about DataTemplates in the Data Templates article.
Implementing this collection allows you to have and display any number of user profiles in your UI, rather than being restricted by screen size as your original example would be.
Now finally, on to saving the data... this can be achieved relatively simply using the following code:
try
{
using (Stream stream = File.Open("ProfileData.bin", FileMode.Create))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter .Serialize(stream, usersList);
}
}
catch { }
One thing to note is that WPF wants us to use the ObservableCollection<T> class when displaying data in the UI, but this class causes problems when serializing data with this method... therefore, you will need to convert your ObservableCollection<T> to a List<T> or similar. However, this can be easily achieved:
List<User> usersList = users.ToList();
You can find out how to de-serialize your data from the C# Serialize List tutorial. You would deserialize (or load the data from the saved file) each time your application starts and re-save the file each time the program closes. You can add an event handler to the Application.Deactivated Event or the Window.Closing which gets called when the application closes, so you can put your code to save the file in there.
Well, I took longer and wrote more than I had expected, so I hope that helps.
I need to realize in C# .NET with WPF a ScrollBar Animation on a RichTextBox Control.
When i click on a button, the animation is supposed to bring me at the end of the text. For this I use the ScrollToEnd() method but i do not know how to perform the animation. I tried things with the BeginAnimation() method but nothing worked.
If anyone of you had any idea, it would be awesome. Thanks!
My XAML :
<Window x:Class="TestWpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="177.811" Width="338.88">
<Grid Margin="0,0,2,-1">
<RichTextBox x:Name="rtb" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="319" ScrollViewer.VerticalScrollBarVisibility="Visible">
<FlowDocument>
<Paragraph>
<Run Text="RichTextBoxR
ichTextBoxRichTextBoxRichTextBoxRic
hTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTe
xtBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRic
hTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextB
oxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRi
extBoxRichTextBoxRichTextBoxRichTextBoxRichTe
xtBoxRichTextBoxRichTextBoxRichTextBoxRichTextBoxRichTe
xtBoxRichTextBoxRich
TextBoxRichT
extBox"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<Button Content="Button" HorizontalAlignment="Left" Margin="122,121,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
</Grid>
My button click method in the XAML.cs :
private void Button_Click_1(object sender, RoutedEventArgs e) { rtb.ScrollToEnd(); }
Thanks a lot !
Best Regards.
Ok i found the solution. I created a new class from RichTextBox properties and added a Dependencyproperty to make it works :
class ExtRichTextBox : RichTextBox
{
public static DependencyProperty CurrentVerticalOffsetProperty =
DependencyProperty.Register("CurrentVerticalOffset", typeof(double), typeof(ExtRichTextBox), new PropertyMetadata(new PropertyChangedCallback(OnVerticalChanged)));
private static void OnVerticalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ExtRichTextBox extRtb = d as ExtRichTextBox;
extRtb.ScrollToVerticalOffset((double)e.NewValue);
}
public double CurrentVerticalOffset
{
get { return (double)this.GetValue(CurrentVerticalOffsetProperty); }
set { this.SetValue(CurrentVerticalOffsetProperty, value); }
}
}
Sure you need to replace the old control by the new one then you use a storyboard to animate the scrollbar :
private void Button_Click_1(object sender, RoutedEventArgs e)
{
DoubleAnimation vertAnim = new DoubleAnimation();
vertAnim.From = rtb.VerticalOffset;
vertAnim.To = 100;
vertAnim.DecelerationRatio = .2;
vertAnim.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
Storyboard sb = new Storyboard();
sb.Children.Add(vertAnim);
Storyboard.SetTarget(vertAnim, rtb);
Storyboard.SetTargetProperty(vertAnim, new PropertyPath(ExtRichTextBox.CurrentVerticalOffsetProperty));
sb.Begin();
}
Just replace coordonnates given to vertAnim.To property to scroll at the position you want.