Элемент управления IntegerUpDown Изменение фона, когда текстовое поле IsFocused

Названия таблиц и столбцов не могут быть заменены параметрами в PDO.

В этом случае вы просто захотите фильтровать и дезинфицировать данные вручную. Один из способов сделать это - передать сокращенные параметры функции, которая будет выполнять запрос динамически, а затем использовать оператор switch() для создания белого списка допустимых значений, которые будут использоваться для имени таблицы или имени столбца. Таким образом, пользовательский ввод никогда не попадает непосредственно в запрос. Например:

function buildQuery( $get_var ) 
{
    switch($get_var)
    {
        case 1:
            $tbl = 'users';
            break;
    }

    $sql = "SELECT * FROM $tbl";
}

Не оставляя случая по умолчанию или используя случай по умолчанию, который возвращает сообщение об ошибке, вы убедитесь, что используются только значения, которые вы хотите использовать.

0
задан Craig Martin 16 January 2019 в 00:01
поделиться

3 ответа

Тот же триггер в исходном коде IntegerUpDown, поэтому внешний триггер больше не действует.

Исходный код IntegerUpDown:

<Trigger Property="IsFocused" Value="True">
    <Setter TargetName="PART_TextBox"
          Property="FocusManager.FocusedElement"
          Value="{Binding ElementName=PART_TextBox}" />
</Trigger>

Я пытался использовать события GotFocus и LostFocus.

xaml:

<xctk:IntegerUpDown x:Name="Day" 
     LostFocus="IntegerUpDown_LostFocus" 
     GotFocus="IntegerUpDown_GotFocus"  
     Focusable="True"  
     Value="{Binding DayText, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style="{StaticResource IntegerUpDownStyle}" Minimum="{Binding MinimumDateSelection}" Maximum="{Binding MaximumDateSelection}">
   <xctk:IntegerUpDown.Watermark>
        <TextBlock Text="Day" Foreground="{StaticResource OffsetWhiteBrush}" Margin="0,0,60,0"/>
    </xctk:IntegerUpDown.Watermark>
</xctk:IntegerUpDown>

cs код:

private void IntegerUpDown_GotFocus(object sender, RoutedEventArgs e)
{
    Day.Background = new SolidColorBrush(Colors.Gray);
}

private void IntegerUpDown_LostFocus(object sender, RoutedEventArgs e)
{
    Day.Background = new SolidColorBrush(Colors.DarkGray);
}
0
ответ дан J.B.D 16 January 2019 в 00:01
поделиться

Я пытался решить эту проблему в своем собственном приложении, и оно закончено. Вот код:

<Window
x:Class="WpfApp16.MainWindow"
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:local="clr-namespace:WpfApp16"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Window.Resources>
    <Style x:Key="IntegerUpDownStyle" TargetType="xctk:IntegerUpDown">
        <Style.Triggers>
            <EventTrigger RoutedEvent="ValueChanged">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation
                                Storyboard.TargetProperty="Background.Color"
                                From="DarkGray"
                                To="Transparent"
                                Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>

            </EventTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<StackPanel>

    <xctk:IntegerUpDown Width="200" Style="{StaticResource IntegerUpDownStyle}">
        <xctk:IntegerUpDown.Background>
            <SolidColorBrush Color="Transparent" />
        </xctk:IntegerUpDown.Background>
    </xctk:IntegerUpDown>
</StackPanel>

Для получения дополнительной информации посмотрите этот линк: Проблема зависимости анимации WPF [ 111]

0
ответ дан FranklinLee 16 January 2019 в 00:01
поделиться

Увидев ответ от @ J.B.D, я отредактировал ControlTemplate для элемента управления IntegerUpDown, чтобы сменить обратную сторону.

<ControlTemplate x:Key="ControlControlTemplate1" TargetType="{x:Type Control}">
            <xctk:ButtonSpinner x:Name="PART_Spinner" AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ButtonSpinnerLocation="{Binding ButtonSpinnerLocation, RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" HorizontalContentAlignment="Stretch" IsTabStop="False" ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}" VerticalContentAlignment="Stretch">
                <xctk:WatermarkTextBox x:Name="PART_TextBox" AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}" AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}" AcceptsReturn="False" BorderThickness="0" ContextMenu="{TemplateBinding ContextMenu}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="True" IsUndoEnabled="True" MinWidth="20" MaxLength="{Binding MaxLength, RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}" TextWrapping="NoWrap" TabIndex="{TemplateBinding TabIndex}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}">
                    <xctk:WatermarkTextBox.Style>
                        <Style TargetType="{x:Type xctk:WatermarkTextBox}">
                            <Setter Property="Background" Value="{StaticResource DarkGreyBrush}" />
                            <Style.Triggers>
                                <Trigger Property="IsFocused" Value="True">
                                    <Setter Property="Background" Value="{StaticResource LightGreyBrush}" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </xctk:WatermarkTextBox.Style>
                </xctk:WatermarkTextBox>

            </xctk:ButtonSpinner>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlMouseOverBorderKey, TypeInTargetAssembly={x:Type Themes:ResourceKeys}}}"/>
                </Trigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="False"/>
                        <Condition Binding="{Binding AllowTextInput, RelativeSource={RelativeSource Self}}" Value="False"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/>
                </MultiDataTrigger>
                <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                    <Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/>
                </DataTrigger>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlSelectedBorderKey, TypeInTargetAssembly={x:Type Themes:ResourceKeys}}}"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
                <Trigger Property="IsFocused" Value="True">
                    <Setter Property="FocusManager.FocusedElement" TargetName="PART_TextBox" Value="{Binding ElementName=PART_TextBox}"/>
                    <Setter TargetName="PART_TextBox" Property="Visibility" Value="Hidden" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

Пожалуйста, посмотрите на начало шаблона элемента управления и WatermarkTextBox. WatermarkTextBox.Style - это то, что я добавил, чтобы изменить фон, когда текстовое поле сфокусировано.

Чтобы переопределить шаблон COntrolTemplate, щелкните правой кнопкой мыши элемент управления IntegerUpDown и нажмите «Изменить шаблон»

.
0
ответ дан Craig Martin 16 January 2019 в 00:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: