1

私は理論上のクラス用のチューリングマシンシミュレーターを開発しており、マシンが言語を受け入れるかどうかに基づいて入力領域の背景色を変更しようとしています(基本的に、有効かどうかに応じて一方の色をもう一方の色に変更します)入力)。

いくつかの入力例を提供したいので、それはComboBoxである必要があります。教授は自分の入力をテストする必要があるため、編集可能である必要があります。だから、ここにいます。

ComboBox.BackgroundプログラムとXAML(プロパティエディター経由)の両方でプロパティを設定しようとしましたが、どちらも機能しません。ただし、設定は問題ありませんComboBox.Foreground

これが私のXAMLです。

<Window x:Class="Turing.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Turing Machine Emulator" Height="400" Width="600" Loaded="onload" MinHeight="500" MinWidth="600">

    <Grid>
        <ComboBox x:Name="drpProblem" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="changeproblem"/>
        <Label x:Name="lblDescription" Content="Language Description" Margin="135,7,90,0" VerticalAlignment="Top"/>
        <Grid Margin="10,0,10,35" Height="24" VerticalAlignment="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="10*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="10*"/>
            </Grid.ColumnDefinitions>
            <Label x:Name="lblLeft" Content="left" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="0" Margin="0,0,10,0" FontFamily="Consolas"/>
            <Label x:Name="lblRight" Content="right" Grid.Column="2" VerticalContentAlignment="Center" Padding="0" Margin="10,0,0,0" FontFamily="Consolas"/>
            <Label x:Name="lblCenter" Content="cur" Grid.Column="1" Height="24" Padding="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Background="#FFC5FFA4" FontFamily="Consolas" FontSize="16"/>
        </Grid>
        <Button x:Name="btnIterate" Content="Iterate" Margin="10,0,0,64" Height="20" VerticalAlignment="Bottom" Click="btnIterate_Click" HorizontalAlignment="Left" Width="236"/>
<!-- This one right here -->
        <ComboBox x:Name="txtInput" Height="23" Margin="10,0,10,89" Text="Input String" VerticalAlignment="Bottom" FontFamily="Consolas" VerticalContentAlignment="Center" TextBoxBase.TextChanged="cboGetInput" BorderBrush="{x:Null}" Foreground="Black" Background="#FF874343" IsEditable="True" />
        <TextBox x:Name="txtMs" Height="20" Margin="251,0,172,64" TextWrapping="Wrap" Text="wait (seconds)" VerticalAlignment="Bottom"/>
        <Button x:Name="btnAutoRun" Content="AutoRun" Margin="0,0,10,64" Click="btnAutoRun_Click" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="157"/>
        <TextBox x:Name="txtTM" Margin="10,38,10,142" TextWrapping="Wrap" Text="Language" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" FontFamily="Consolas" FontSize="14"/>
        <Button x:Name="btnLoadLang"  Content="Load" Margin="10,0,10,117" Height="20" VerticalAlignment="Bottom" Click="changeproblem"/>
        <StatusBar Height="30" VerticalAlignment="Bottom">
            <TextBlock x:Name="stTXTName" Text="StateName"/>
            <Separator/>
            <TextBlock x:Name="stTXTDescription" Text="StateDescription"/>
            <Separator/>
            <TextBlock x:Name="stTXTTransition" Text="NextTransition"/>
            <Separator/>
            <TextBlock x:Name="stTXTNext" Text="NextState"/>
        </StatusBar>

    </Grid>
</Window>

これが私が周りの色を変えようとするために使っているコードです:

if (TM.AcceptsString(txtInput.Text))
{
    txtInput.Background = Brushes.LightGreen;
    txtInput.Foreground = Brushes.LightGreen;
}
else
{
     txtInput.Background = Brushes.Pink;
     txtInput.Foreground = Brushes.Pink;
}

前景は期待どおりに変更されますが、背景色はデフォルトの白から変更されることはありません。私は何か間違ったことをしていますか?ComboBox私が行ったように、プロパティを設定する必要があるコンポーネントコントロールはありTextBoxBase.TextChangedますか?

4

2 に答える 2

0

同様の問題があり、Visual Studio 2015 で ComboBox のテンプレートを自動生成することで解決できました (デザイン ウィンドウで ComboBox を右クリック -> テンプレートの編集 -> コピーの編集)

于 2016-07-23T16:14:50.583 に答える
0

ComboBox の FlatStyle 属性を FlatStyle.Flat に設定します。これにより、Win 7 Aero テーマがオンになっているときに発生した同様の問題が解決されました。ComboBox の背景色が、デフォルトの FlatStyle 設定 FlatStyle.Standard に表示されません。

于 2013-03-03T22:04:27.227 に答える