当我运行wpf项目应用程序时,组合框未响应鼠标单击,并且未显示下拉列表

时间:2018-09-06 07:43:00

标签: wpf

我正在研究wpf应用程序,我有点新。

我已经将组合框添加到了第一个子菜单和第二个子组合框的堆栈面板中。

看下面的代码:

class Program
{
    static void Main(string[] args)
    {
        HImage Image = new HImage(@"08_09_09_41_33_582_OK_000000153000.png");
        double MidpointRow = 1053.5210373923057, MidpointCol = 1223.5205413999142;

        int iCounter = 0;

        while (true)
        {
            HNCCModel model = new HNCCModel(@"000000135000Mark_0.ncm");

            HXLDCont hxCont = new HXLDCont();
            hxCont.GenRectangle2ContourXld(
                721.9213759213759,
                1775.862648221344,
                -0.99483767363676778,
                72,
                14.5);

            HTuple htRowXLD, htColXLD;
            hxCont.GetContourXld(out htRowXLD, out htColXLD);
            HTuple htRadius = new HTuple();
            htRadius = new HTuple(htRowXLD.TupleSub(MidpointRow).TuplePow(2) + htColXLD.TupleSub(MidpointCol).TuplePow(2)).TupleSqrt();
            HRegion hrAnnulus = new HRegion();
            hrAnnulus = hrAnnulus.GenAnnulus(MidpointRow, MidpointCol, htRadius.TupleMin() - 5.0, htRadius.TupleMax() + 5.0);

            HImage hiTemp = Image.Clone();
            HImage hiTemp2 = hiTemp.Rgb1ToGray();
            HImage hiTemp3 = hiTemp2.ReduceDomain(hrAnnulus);

            HTuple htRow, htColumn, Angle, Score;

            model.FindNccModel(hiTemp3, -0.39, 6.29, 0.65, 1, 0, "true", 0, out htRow, out htColumn, out Angle, out Score);

            hxCont.DisposeIfNotNull();
            hrAnnulus.DisposeIfNotNull();
            model.Dispose();

            hiTemp.DisposeIfNotNull();
            hiTemp2.DisposeIfNotNull();
            hiTemp3.DisposeIfNotNull();

            Console.WriteLine(iCounter++.ToString());
        }
    }
}

public static class DL_HalconUtilityClass
{
    public static HRegion GenAnnulus(this HRegion region, double dCenterRow, double dCenterColumn, double dRadiusSmall, double dRadiusBig)
    {
        region.GenEmptyRegion();

        if (dRadiusSmall > dRadiusBig)
        {
            throw new NotSupportedException("Wrong input parameters. Small radius is bigger than big radius.");
        }

        HRegion hrCircleSmall = new HRegion(dCenterRow, dCenterColumn, dRadiusSmall);
        HRegion hrCircleBig = new HRegion(dCenterRow, dCenterColumn, dRadiusBig);

        region = new HRegion();
        region = hrCircleBig.Difference(hrCircleSmall);

        hrCircleSmall.Dispose();
        hrCircleBig.Dispose();

        return region;
    }

    public static void DisposeIfNotNull(this HImage hiImage)
    {
        if (hiImage != null) hiImage.Dispose();
    }

    public static void DisposeIfNotNull(this HRegion hrRegion)
    {
        if (hrRegion != null) hrRegion.Dispose();
    }

    public static void DisposeIfNotNull(this HObject hoObject)
    {
        if (hoObject != null) hoObject.Dispose();
    }
}

将数据加载到组合框并处理选择更改的代码如下:

<Grid>
        <StackPanel>
        <Menu Background="Chocolate" Height="30" VerticalAlignment="Top">
        <MenuItem Header="File"></MenuItem>
        <MenuItem Header="Edit"></MenuItem>
        <MenuItem Header="View"></MenuItem>
        <MenuItem Header="Help"></MenuItem>
        </Menu>
            <ComboBox Width="100" Height="30" Loaded="Cbox_Load" Margin="30" SelectionChanged="Cbox_Changed_event">

            </ComboBox>


        </StackPanel>
<ScrollViewer>
------rest of controls---
</ScrollViewer>
</Grid>

问题:运行项目时,我无法单击组合框以选择组合框项目。组合框显示为已禁用

请指导。

1 个答案:

答案 0 :(得分:0)

在同一单元格中有两个控件StackPanel和ScrollViewer:row =“ 0”,column =“ 0”。将它们放在不同的单元格中。

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>       
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            <Menu Background="Chocolate" Height="30" VerticalAlignment="Top">
                <MenuItem Header="File"></MenuItem>
                <MenuItem Header="Edit"></MenuItem>
                <MenuItem Header="View"></MenuItem>
                <MenuItem Header="Help"></MenuItem>
            </Menu>
            <ComboBox Width="100" Height="30" Loaded="Cbox_Load" Margin="30" SelectionChanged="Cbox_Changed_event">
            </ComboBox>
        </StackPanel>
        <ScrollViewer Grid.Row="1">    
            <!-- ... -->
        </ScrollViewer>
    </Grid>