WPF TextBlock Click Event
Actually, for WPF TextBlock Component, there is no click event. The best replacement is Mouse Down Event,
Like this:
Code
text1.MouseDown += text1_MouseDown; |
Adding a WPF control into a panel programmatically
The best way to design an interface for WPF is using xaml. However, in some situation, we need to change the layout in code. For example, we select a category view, we need to add a new block in a stack panel.
For example:
Code
TextBlock text1 = new TextBlock(); | |
text1.Text = grid.HeaderText; | |
LinearGradientBrush style = this.FindResource("LeftHeaderBrush") as LinearGradientBrush ; | |
text1.Background= style; | |
text1.Height = 100; | |
inactivePanels.Children.Add(text1); |
I started to love Visual Studio 2013
I started to use Visual Studio 2013 for some new projects. I found there are a number of new features make our life easier, such as displaying the number of references for each class and method.
Those small features help us to build the applications easier.
WPF Animation
I built a feature to have an animation on the wide of a panel and the user click the minimize button. I wish to create a shrinking effect.
The best way I found is using DoubleAnimationUsingKeyFrames. This kind of animation can targeting any properties which is using a double as its value, such as Wide. Finally, I put the into a storyboard. Like the following
Code
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); | |
LinearDoubleKeyFrame ad3 = new LinearDoubleKeyFrame(); | |
ad3.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0)); | |
ad3.Value = ActualWidth; | |
LinearDoubleKeyFrame ad = new LinearDoubleKeyFrame(); | |
ad.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0,0,6)); | |
ad.Value = 0; | |
Storyboard strbStoryboard = new Storyboard(); | |
strbStoryboard.Children.Add(da); | |
Storyboard.SetTargetProperty(da, new PropertyPath("(FrameworkElement.Width)")); | |
Storyboard.Begin(this); |
The example is from my opensource project, advgen contact manager
WPF:Show and Hide Button
In Winform, to show and hide button is easy. There is a property calls visible in Button class. You just need to set it to be True and Hide. That is a simple bool type. In WPF, that is simple too, but that is not a simple bool type. That is Visibility Type.
You just need to do that:
Show:
Code
btnMax.Visibility= System.Windows.Visibility.Visible; |
Hide:
Code
btnMax.Visibility= System.Windows.Visibility.Hidden; |