Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 706337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:09:17+00:00 2026-05-14T04:09:17+00:00

I have a problem that i cant solve :( I have a user control

  • 0

I have a problem that i cant solve 🙁
I have a user control (xaml file and cs file)

in xaml it’s like:

<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="Demo.CtrlContent"
x:Name="UserControl"
d:DesignWidth="598.333" d:DesignHeight="179.133" xmlns:Demo="clr-namespace:Demo" >
<UserControl.Resources>
    <Storyboard x:Key="SBSmall">
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(FrameworkElement.Width)">
            <SplineDoubleKeyFrame KeyTime="00:00:01" Value="I WANT TO BIND VALUE HERE"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>
<Border BorderBrush="#FFC2C0C1" CornerRadius="3,3,3,3" BorderThickness="1,1,1,1" RenderTransformOrigin="0.5,0.5" x:Name="border" Margin="1,3,1,3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="300">

and .cs file:

public partial class CtrlContent {

    private mindef W { get { return (mindef) Window.GetWindow(this); } }
    public double MedWidth { // I WANT BIND THIS VALUE GO TO STORYBOARD VALUE IN XAML ABOVE
        get {
            double actualW;
            if(W == null) actualW = SystemParameters.PrimaryScreenWidth;
            else actualW = W.WrapMain.ActualWidth;
            return actualW - border.Margin.Left - border.Margin.Right;
        }
    }
    public double SmlWidth { get { return MedWidth / 2; } }

    public CtrlContent () { this.InitializeComponent(); }
    public CtrlContent (Content content) {
        this.InitializeComponent();
        Document = content;
    }
}

in my .cs file there’s a property called MedWidth, and in XAML file there’s a storyboard called: SBSmall
I want to bind my storyboard value to my property in class ctrlcontent.

*the idea is, the storyboard is an animation to resize the control to a certain width depends on its parent container (the width is dynamic)

anybody? please 🙂
thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:09:17+00:00Added an answer on May 14, 2026 at 4:09 am

    In your CtrlContent constructor, assign DataContext = this;

    Then in your xaml:

    <SplineDoubleKeyFrame Value="{Binding Path=MedWidth}"
    

    That’s the minimum required to get the xaml to read from your MedWidth property at least once at startup. If you want the databinding to update when the MedWidth property changes value, you’ll need to implement INotifyPropertyChanged on CtrlContent and send the change notifications.

    Note that assigning this to the DataContext is a bit of a sloppy hack. It exposes your entire class to anything running around on the xaml side of the house. A better separation of UI from logic would be to create a separate small class that is used only for data binding, and assign that to DataContext in the CtrlContent constructor. That will also keep the INotifyPropertyChanged overhead out of your main class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Copying the .hg directory is a completely valid way to… May 14, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer It depends a bit on the programming language. In C/C++… May 14, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer // Get the weeks in a month DateTime date =… May 14, 2026 at 4:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.