D
D
Dmitry Bashinsky2017-11-05 20:25:00
WPF
Dmitry Bashinsky, 2017-11-05 20:25:00

User Control need to flip properties?

Hello, there are 2 questions about UserControl.
Here I have a control, I added a couple of DependencyProperty to it and made some EditableTextBlock when double-clicking, the IsEditMode property changes and the TextBox is hidden / shown, everything works, I got what I wanted, but besides these properties, I want to change some more properties
1) Is it really so it is necessary to forward all properties everywhere? in the example, only the font, but there can be a lot of things.

<UserControl
    x:Class="SlideMenu.Controls.EditableTextBlock"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:SlideMenu.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Name="uc"
    d:DesignHeight="25"
    d:DesignWidth="100"
    mc:Ignorable="d">
    <Grid>
        <TextBlock
            FontFamily="{Binding ElementName=uc, Path=FontFamily}"
            FontSize="{Binding ElementName=uc, Path=FontSize}"
            FontWeight="{Binding ElementName=uc, Path=FontWeight}"
            MouseDown="TextBlock_MouseDown"
            Text="{c:Binding ElementName=uc,
                             Path=Text}"
            TextAlignment="{Binding ElementName=uc, Path=TextAlignment}" />
        <TextBox
            FontFamily="{Binding ElementName=uc, Path=FontFamily}"
            FontSize="{Binding ElementName=uc, Path=FontSize}"
            FontWeight="{Binding ElementName=uc, Path=FontWeight}"
            MouseDoubleClick="TextBox_MouseDoubleClick"
            Text="{c:Binding ElementName=uc,
                             Path=Text}"
            TextAlignment="{Binding ElementName=uc, Path=TextAlignment}"
            Visibility="{c:Binding ElementName=uc,
                                   Path=IsEditMode}" />
    </Grid>
</UserControl>

2) The UserControl has a Content property that just hangs in the way and if I do this
<Controls:EditableTextBlock Grid.Column="1" Text="ASDHAJSHDGA" HorizontalAlignment="Left"  Width="108">
            qwhuejghhqwe
        </Controls:EditableTextBlock>

all my control is simply replaced by Content, how can I remove this feature? and how do I use this Content, when I tried to bind it to ContentControl or ContentPresenter I got errors, and in general the studio crashes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LootKeeper, 2017-11-08
@BashkaMen

1) Yes, but this can be simplified using the DataContext, you can bind everything you need through the ViewModel without the Dependency Property

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question