locked
Predefined controls into a User Control RRS feed

  • Question

  • Hi,

    I am doing a project in which I have a scrollviewer In which I have a Grid in which I have a rectangle sketch - in which I have some 5 to 6 text blocks wherein I wanted to make this as a user control and wanted to use in the other projects wherein I do not want to go to the XAML code to edit the textblock Content instead I should directly edit the textblocks....

    Could anyone help me?

    I have attached the XAML code and the screenshot for the same.

    main window

    <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"
     xmlns:local="clr-namespace:usercontrolsBuildScreens" xmlns:System_Windows_Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" x:Name="Screen_1_Name"
     x:Class="usercontrolsBuildScreens.Screen_1"
     Width="1280" Height="840">

     <Grid x:Name="LayoutRoot" Background="White">
      <local:scrollRectangle HorizontalAlignment="Left" Margin="8,225,0,0" Width="309" VerticalAlignment="Top" Height="194"/>
     </Grid>
    </UserControl>

     

    usercontrol window

    <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="usercontrolsBuildScreens.scrollRectangle"
     x:Name="UserControl"
     d:DesignWidth="640" d:DesignHeight="480" Width="260" Height="280">

     <Grid x:Name="LayoutRoot">
      <ScrollViewer Margin="2,2,2,3" Style="{DynamicResource ScrollViewer-Sketch-List}">
       <Grid Height="275">
        <TextBlock Margin="8,8,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,28,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,48,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,68,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,88,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,108,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,128,27,0" Style="{DynamicResource BasicTextBlock-Sketch}" VerticalAlignment="Top" Height="21" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,148,27,131" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,111" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,91" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,71" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,51" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,31" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,11" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
        <TextBlock Margin="8,0,27,-9" Style="{DynamicResource BasicTextBlock-Sketch}" Text="Text1" VerticalAlignment="Bottom" Height="21" Cursor="Hand"/>
       </Grid>
      </ScrollViewer>
     </Grid>
    </UserControl>

    http://www.box.net/shared/ai0v7kv5ac

    Friday, May 21, 2010 11:55 AM

All replies

  • If you are editing the scrollRectangle control you should be able to edit the textblock content directly on the design surface, is that not happening? 
    Friday, May 21, 2010 1:19 PM
    Moderator
  • Hi Chuck,

    I am not able to edit the scrollRectangle too. which is a user control and I have added a new item as User Control for the project and done the XAML coding as the previous attached code when I call this user control in the main window xaml page, I am not able to edit the textboxes in the same page itself rather I could edit in the User Control page.

    Please help me how can I make use of this control to edit in the MainWindow rather than in the User Control page.

    Thanks in advance.

     

    Monday, May 24, 2010 5:22 AM
  • If your active document is scrollRectange.xaml you should be able to edit the text in the textboxes, if it is screen_1.xaml, you can't edit the embedded usercontrol directly.

     

    It sounds like your goal is to have different text for different instances of the ScrollRectangle UserControl?  If so, you can't edit them in the way you are suggesting.  To do that you would have to expose Dependency properties on the ScrollRectangle UserControl and databind the textblocks to the properties.  Then you could set them differently for each instantiation of the UserControl.

    Monday, May 24, 2010 1:38 PM
    Moderator