I added my UserControl , I moved the necessary code there from Xaml added usings. I added the method I needed to codebook, but now I don’t see these elements when launching the application.

Do I need to call this UserControl additionally?

 public sealed partial class ImageManipulatorControl:UserControl { public ImageManipulatorControl() { this.InitializeComponent(); } private void CollageImgage1_Manipulation(object sender, ManipulationDeltaRoutedEventArgs e) { Manipulation(e, CollageImg1); } private void Manipulation(ManipulationDeltaRoutedEventArgs e, Image image) { CompositeTransform ct = (CompositeTransform)image.RenderTransform; ct.ScaleX *= e.Delta.Scale; ct.ScaleY *= e.Delta.Scale; ct.TranslateX += e.Delta.Translation.X; ct.TranslateY += e.Delta.Translation.Y; ct.Rotation += Math.PI * e.Delta.Rotation; } } 

XAML

 <UserControl x:Class="PhotoRedactor.Controls.ImageManipulatorControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:PhotoRedactor" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="using:PhotoRedactor.ViewModels" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <UserControl.Resources> <viewModels:EffectsViewModel x:Name="EffectsViewModel"/> <viewModels:MainViewModel x:Name="MainViewModel"/> </UserControl.Resources> <Grid Background="GreenYellow" HorizontalAlignment="Center" VerticalAlignment="Center" Width="2235" Height="1316" Margin="122,217,-1957,-1233"> <Grid.ColumnDefinitions > <ColumnDefinition Width="313*"/> <ColumnDefinition Width="1053*"/> </Grid.ColumnDefinitions> <Canvas Margin="0" Grid.Row="0" Grid.Column="0" IsTapEnabled="False" x:Name="CollageArea" IsHoldingEnabled="False" IsRightTapEnabled="False" IsDoubleTapEnabled="False" VerticalAlignment="Center" HorizontalAlignment="Center" DataContext="{StaticResource EffectsViewModel}"> </Canvas> <Image Width="525" Height="331" Canvas.Top="-388" Canvas.Left="-140" x:Name="CollageImg1" ManipulationMode="All" Source="{Binding CollageImg1}" RenderTransformOrigin="0.5,0.5" ManipulationDelta ="CollageImgage1_Manipulation" Visibility="{Binding IsCollageImg1Visible, Converter={StaticResource BooleanToVisibilityConverter}}" DataContext="{StaticResource EffectsViewModel}" Margin="21,227,9.6,758"> <Image.RenderTransform> <CompositeTransform/> </Image.RenderTransform> </Image> </Grid> 

    1 answer 1

    Well yes.

     <Page ...> <Grid Background=...> <local:ТутИмяВашегоЮзерКонтрола /> </Grid> </Page> 

    An investigation into the comments revealed the following:

    It is necessary to set the DataContext for UserControl 'in the external container (in our case, in Page ), thus the DataContext will be common for the external window and control. Then, you need to bind to the properties of the DataContext via Binding .

    • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin
    • This is on condition that you need to use the same instance of the class - SmiLe