Usercontrol properties
-
Hi, I developed a Usercontrol which has a slidercontrol and the textbox displaying the current slider value. I need to adjust only the slider width from the widow XAML that uses the Usercontrol . Can anyone let me know how to achieve this. Thanks
-
Hi, I developed a Usercontrol which has a slidercontrol and the textbox displaying the current slider value. I need to adjust only the slider width from the widow XAML that uses the Usercontrol . Can anyone let me know how to achieve this. Thanks
Hi... An example in the Codeproject has this implementation. I am extracting from it and pasting it here. in XAML.cs, <pre> private void CenteringSlider_LostMouseCapture(object sender, MouseEventArgs e) { // change the size of the ellipse when slider value is change // for this example the slider max is 80 // and the slider min is -80 PlumEllipse.Width = PlumEllipse.Height = (100 + e.NewValue); } private void CenteringSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { // set a 500ms duration Duration returnToCenterDuration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); CenteringSlider.BeginAnimation(Slider.ValueProperty, new DoubleAnimation(CenteringSlider.Value, 0, returnToCenterDuration, FillBehavior.Stop)); // set the slider value to zero // otherwise the slider will return to the last postion after the animation CenteringSlider.Value = 0; } </pre> Please search for the full project in codeproject itself. Thank you, Ramm
-
Hi, I developed a Usercontrol which has a slidercontrol and the textbox displaying the current slider value. I need to adjust only the slider width from the widow XAML that uses the Usercontrol . Can anyone let me know how to achieve this. Thanks
Assuming you have exposed a property in your usercontrol for the width, all you need to do in the control itself is add
Width="{Binding MyWidthProperty}"
in the XAML for the slider. Then, the hosting item just setsMyWidthProperty="nnn"
(wherennn
is the width you want)."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.
-
Assuming you have exposed a property in your usercontrol for the width, all you need to do in the control itself is add
Width="{Binding MyWidthProperty}"
in the XAML for the slider. Then, the hosting item just setsMyWidthProperty="nnn"
(wherennn
is the width you want)."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.
Thanks for the reply , should i expose the width as the dependency property. One more question, if i need to modify other properties like Height, MinWidth,MinHeight then should i register those properties also as a dependency property in the user control. Thanks
-
Assuming you have exposed a property in your usercontrol for the width, all you need to do in the control itself is add
Width="{Binding MyWidthProperty}"
in the XAML for the slider. Then, the hosting item just setsMyWidthProperty="nnn"
(wherennn
is the width you want)."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.
I am looking for a variation of this answer as well (assuming I read the question right). I have a simple UserControl that has 3 controls which I plan to use to standardise the visual look. The only part of this control that will very is the text on the button. I would like to be able to set this within the XAML as once set it will not change. For example, i would like to be able to do something like this. <Views:CurrentStatusView ButtonText="Proceed"/> If I expose a property I am able to set the value, but how do I use this within the user control, I have tried Binding, setting the value in the constructor etc with no success. Many thanks
Just racking up the postings
modified on Thursday, September 3, 2009 10:26 AM
-
I am looking for a variation of this answer as well (assuming I read the question right). I have a simple UserControl that has 3 controls which I plan to use to standardise the visual look. The only part of this control that will very is the text on the button. I would like to be able to set this within the XAML as once set it will not change. For example, i would like to be able to do something like this. <Views:CurrentStatusView ButtonText="Proceed"/> If I expose a property I am able to set the value, but how do I use this within the user control, I have tried Binding, setting the value in the constructor etc with no success. Many thanks
Just racking up the postings
modified on Thursday, September 3, 2009 10:26 AM
Here's a sample that shows how to do this (first of all, the XAML):
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WpfSample.CurrentStatusView"
x:Name="UserControl"
d:DesignWidth="640" d:DesignHeight="480"><Grid x:Name="LayoutRoot"> <Button HorizontalAlignment="Left" VerticalAlignment="Top" Content="{Binding ButtonText}"/> </Grid>
</UserControl>
then the code behind
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;namespace WpfSample
{
/// <summary>
/// Interaction logic for CurrentStatusView.xaml
/// </summary>
public partial class CurrentStatusView : UserControl
{
public CurrentStatusView()
{
this.InitializeComponent();
ButtonText = "Hello there";
DataContext = this;
}public static DependencyProperty ButtonTextProperty = DependencyProperty.Register( "ButtonText", typeof(string), typeof(CurrentStatusView)); public string ButtonText { get { return GetValue(ButtonTextProperty).ToString(); } set { SetValue(ButtonTextProperty, value); } }
}
}Finally, you set it with:
<WpfSample:CurrentStatusView ButtonText="Howdy" HorizontalAlignment="Left" Margin="27,42,0,0" VerticalAlignment="Top" />
"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.
-
Thanks for the reply , should i expose the width as the dependency property. One more question, if i need to modify other properties like Height, MinWidth,MinHeight then should i register those properties also as a dependency property in the user control. Thanks
Yes and yes.
"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.