locked
Blend + UserControl + Custom Button RRS feed

  • Question

  • TLDR: Use Blend to create a WPF Control Library, create a custom button, build the lib, then put it on the Toolbox in Visual Studio, drag an instance onto the MainWindow and doubleclick to change the button's text. BUT Content is not a string but a Button.

    Hey guys,

    I already spent a huge amount of time on reading the official documentation, searching the web and on just trying around. What I would like to do is create a custom button for one of my WPF applications I wrote in VS2012. So I decided to work directly in Blend to create a control that could be shared through all my projects. The issue I'm stuck with is that once I have built the Control Library with my custom UserControl and put it onto the ToolBox in VS2012 I cannot access the button's text and its events like OnClick().

    I'm coming from a WinForms and Qt background, so please have some patience with me. :-) WPF is nice but it seems kinda hard to learn.

    The Content field in the properties usually lets me change the button text, but for my custom button it literally says "Button" and I can't change anything to it. It also does not provide the normal button events/function.

    What did I do wrong or what step did I miss?

    step-by-step workflow (just in case someone wants to follow):

    1: I create a new project in Blend: WPF Control Library (Visual C#, v4.5) -> name: MyControlLibrary

    2: First I delete UserControl1 because I want to start from scratch.

    3: Add new item -> UserControl -> name: MyButtonWhatSoEver

    4: Right-Click on the object in the scene -> Make Into Control -> ControlType: Button, Style: MyButtonStyle, Resource Dictionary: MyResourceDict -> OK

    5: Add a white Rectangle (serves as the button's background, no fancy stuff so far :-) ) to the grid but let the ContentPresenter object be the topmost one.

    6: Save and build the control library, switch to VS2012 where my WPF Application project is opened.

    7. Right-click on the Toolbox -> Choose Items... -> WPF Components -> Browse... -> select  MyControlLibrary.dll -> OK

    8: Drag an instance of the new Control from the Toolbox onto the grid of the main window.

    9a: Go to Properties -> find Content -> want to change the button text -> FAIL!

    9b: DoubleClick the item on the grid to edit the button text -> FAIL! -> VS jumps into code and creates an OnLoaded method.

    Any help is much appreciated! Thanks in advance.

    • Edited by overtoxy Thursday, May 8, 2014 11:27 AM
    Thursday, May 8, 2014 11:13 AM