Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Usercontrol properties

Usercontrol properties

Scheduled Pinned Locked Moved WPF
wpftutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krishnan s
    wrote on last edited by
    #1

    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

    K P 2 Replies Last reply
    0
    • K krishnan s

      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

      K Offline
      K Offline
      Krishna Aditya
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • K krishnan s

        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

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        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 sets MyWidthProperty="nnn" (where nnn 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.

        My blog | My articles | MoXAML PowerToys | Onyx

        K P 2 Replies Last reply
        0
        • P Pete OHanlon

          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 sets MyWidthProperty="nnn" (where nnn 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.

          My blog | My articles | MoXAML PowerToys | Onyx

          K Offline
          K Offline
          krishnan s
          wrote on last edited by
          #4

          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

          P 1 Reply Last reply
          0
          • P Pete OHanlon

            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 sets MyWidthProperty="nnn" (where nnn 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.

            My blog | My articles | MoXAML PowerToys | Onyx

            P Offline
            P Offline
            PaulPrice
            wrote on last edited by
            #5

            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

            P 1 Reply Last reply
            0
            • P PaulPrice

              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

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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.

              My blog | My articles | MoXAML PowerToys | Onyx

              1 Reply Last reply
              0
              • K krishnan s

                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

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                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.

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups