试图在WPF

时间:2016-02-01 21:04:01

标签: wpf

我正在定制我的验证在我的WPF应用程序中的显示方式。我的应用程序有一个style.xaml,我的大多数控件样式看起来都像下面的文本框样式。

<Style x:Key="TextBoxInputField" TargetType="TextBox" BasedOn="{StaticResource TextBoxFieldBase}">
    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={converters:ValidationErrorsToErrorMessagesConverter}}" />
    <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={converters:ValidationErrorsToBackgroundColorConverter}}" />
    <Setter Property="Validation.ErrorTemplate">
        <Setter.Value>
            <ControlTemplate>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

根据绑定属性是否具有验证错误,设置工具提示和背景。但是当我尝试类似于组合框样式的东西时,背景是根据Snoop设置的,但组合框在UI中看起来不是黄色。

<Style x:Key="ComboBoxValidation" TargetType="ComboBox" BasedOn="{StaticResource ComboBox}">
    <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={converters:ValidationErrorsToBackgroundColorConverter}}" />
    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={converters:ValidationErrorsToErrorMessagesConverter}}" />
    <Setter Property="Validation.ErrorTemplate">
        <Setter.Value>
            <ControlTemplate>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如何更改组合框的背景以在UI中显示?

2 个答案:

答案 0 :(得分:1)

我在一年前遇到过这个问题,它与使用OS Windows样式的WPF有关,无论你的背景颜色如何。要解决这个问题,您需要完全定义组合框样式。我创建了这种需要调整的组合框样式,但可以给你一个想法。

render partial: "sessions/subregion_select"

答案 1 :(得分:0)

我使用VS中的Document Outline窗口为组合框创建模板。我试图保持与你大部分时间使用的名字相匹配的东西。我试图发布与它一起使用的代码,但是它将它放在char限制的答案上。 XAML值得关注......我认为我改变的只是背景=&#34; {TemplateBinding Background}&#34;在几个地方和使用你的转换器的部分。

XAML:

s3 = boto3.client('s3')
ec2 = boto3.client(service_name='ec2', aws_access_key_id=aws_key, aws_secret_access_key=aws_secret_key)

def lambda_handler(event, context):

    # Get the object from the event and show its content type
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')

    try:
        response = s3.get_object(Bucket=bucket, Key=key)
        compressed_file = StringIO.StringIO()
        compressed_file.write(response['Body'].read())
        compressed_file.seek(0)
        decompressed_file = gzip.GzipFile(fileobj=compressed_file, mode='rb')

        successful_tags = 0;
        json_data = json.load(decompressed_file)
        for record in json_data['Records']:
            if record['eventName'] == 'RunInstances':
                instance_user = record['userIdentity']['userName']
                instances_set = record['responseElements']['instancesSet']
                for instance in instances_set['items']:
                    instance_id = instance['instanceId']
                    ec2.create_tags(Resources=[instance_id], Tags=[{'Key':'Owner', 'Value':instance_user}])
                    successful_tags += 1
        return 'Tagged ' + str(successful_tags) + ' instances successfully'
    except Exception as e:
        print(e)
        print('Error tagging object {} from bucket {}'.format(key, bucket))
        raise e