弹出窗口不显示

时间:2014-05-12 07:05:04

标签: c# wpf xaml popupwindow

我正在尝试显示一个以xaml编码的弹出窗口,并在代码隐藏中执行操作。虽然代码被操作,但页面上没有显示窗口(不是窗口):

XAML:

<Popup x:Name="helppopup" AllowsTransparency="True" Margin="10,10,0,13" StaysOpen="True" Placement="Left" IsEnabled="True" VerticalAlignment="Top" Width="100" Height="420" >
    <StackPanel>
        <Grid  MinHeight="100" MinWidth="80" Width="80" Background="#E6F2ECEC">
            <ListView Height="200" Margin="10,40,0,0" x:Name="helppop" VerticalAlignment="Top" Width="100" TabIndex="1"  BorderThickness="3" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Help" Width="100" DisplayMemberBinding="{Binding Path=line}" />
                    </GridView>
                </ListView.View>

`

<DockPanel>
    <Frame x:Name="_configframe" JournalEntry.KeepAlive="True" JournalOwnership="OwnsJournal"  NavigationUIVisibility="Hidden" />

    <Grid Background="#FFFA0000" MinHeight="720" MinWidth="1624" Width="1624">
        <Button Content="Exit To Windows" Height="73" HorizontalAlignment="Left" Margin="45,112,0,0" Name="exittowindows" VerticalAlignment="Top" Width="220" Click="exittowindows_Click" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="452,221,0,0" Name="reportBox" VerticalAlignment="Top" Width="171" />
        <TextBlock Height="22" HorizontalAlignment="Left" Margin="354,222,0,0" Name="textBlock1" Text="Reporting" VerticalAlignment="Top" Width="92" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="354,329,0,0" Name="textBlock3" Text="Authenticate Y/N" VerticalAlignment="Top" Width="95" />
        <TextBox Height="24" HorizontalAlignment="Left" Margin="452,328,0,0" Name="authenticateBox" VerticalAlignment="Top" Width="26" TextChanged="authenticateBox_TextChanged" />
        <Button Content="Exit" Height="50" HorizontalAlignment="Left" Margin="643,556,0,0" Name="exitbutt" VerticalAlignment="Top" Width="126" Click="exitbutt_Click" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="370,368,0,0" Name="textBlock4" Text="tab enable Y/N" VerticalAlignment="Top" Width="79" />
        <TextBox Height="23" HorizontalAlignment="Right" Margin="0,367,1146,0" Name="TabBox" VerticalAlignment="Top" Width="26" TextChanged="TabBox_TextChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="354,261,0,0" Name="textBlock5" Text="salesdb attached" VerticalAlignment="Top" Width="92" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="452,260,0,0" Name="salesBox" VerticalAlignment="Top" Width="120" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="452,448,0,0" Name="printersBox" VerticalAlignment="Top" Width="120" SelectionChanged="printersBox_SelectionChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="354,448,0,0" Name="textBlock6" Text="printers" VerticalAlignment="Top" Width="71" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="586,448,0,0" Name="textBlock7" Text="selected" VerticalAlignment="Top" Width="88" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="643,447,0,0" Name="selectprintBox" VerticalAlignment="Top" Width="281" />
        <TextBox FontSize="26.667" Height="78" HorizontalAlignment="Left" Margin="376,639,0,0" Text="green rabbit company                 ian@greenrabbitcompany.com" TextWrapping="Wrap" VerticalAlignment="Top" Width="482" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="354,405,0,0" Name="textBlock8" Text="Epos enabled Y/N" VerticalAlignment="Top" />
        <TextBox Height="24" HorizontalAlignment="Left" Margin="452,404,0,0" Name="eposBox1" VerticalAlignment="Top" Width="26" TextChanged="eposBox1_TextChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="354,490,0,0" Name="textBlock9" Text="Paper" VerticalAlignment="Top" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="586,490,0,0" Name="textBlock10" Text="Selected" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Right" Margin="0,490,861,0" Name="paperselectedBox1" VerticalAlignment="Top" Width="120" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="452,490,0,0" Name="papercomboBox1" VerticalAlignment="Top" Width="120" SelectionChanged="papercomboBox1_SelectionChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="15,501,0,0" Name="textBlock11" Text="business name" VerticalAlignment="Top" />
        <TextBox Height="24" HorizontalAlignment="Left" Margin="99,500,0,0" Name="nameBox1" VerticalAlignment="Top" Width="227" TextChanged="nameBox1_TextChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="15,543,0,0" Name="textBlock12" Text="address" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="99,543,0,0" Name="addrBox1" VerticalAlignment="Top" Width="279" TextChanged="addrBox1_TextChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="15,584,0,0" Name="textBlock13" Text="vat telephone" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="99,583,0,0" Name="vattel" VerticalAlignment="Top" Width="279" TextChanged="vattel_TextChanged" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="15,462,0,0" Name="textBlock14" Text="Till number" VerticalAlignment="Top" />
        <TextBox Height="24" HorizontalAlignment="Left" Margin="99,461,0,0" Name="tillnoBox1" VerticalAlignment="Top" Width="65" TextChanged="tillnoBox1_TextChanged" />
        <Button Content="load dept/sub" Height="54" HorizontalAlignment="Left" Margin="354,17,0,0" Name="button1" VerticalAlignment="Top" Width="124" Click="loaddept_Click" />
        <Button Content="Load product" Height="54" HorizontalAlignment="Left" Margin="354,87,0,0" Name="button2" VerticalAlignment="Top" Width="124" Click="loadprod_Click" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="493,48,0,0" Name="deptsubBox1" VerticalAlignment="Top" Width="148" IsReadOnly="True" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="493,118,0,0" Name="productBox1" VerticalAlignment="Top" Width="148" IsReadOnly="True" />
        <TextBlock Height="25" HorizontalAlignment="Left" Margin="493,17,0,0" Name="textBlock15" Text="dept\sub filename" VerticalAlignment="Top" Width="130" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="493,89,0,0" Name="textBlock16" Text="product filename" VerticalAlignment="Top" Width="130" />
        <TextBlock Height="22" HorizontalAlignment="Left" Margin="548,302,0,0" Name="textBlock2" Text="Print shift Y/N" VerticalAlignment="Top" Width="83" />
        <TextBox Height="23" HorizontalAlignment="Right" Margin="0,300,950,0" Name="printShiftBox1" VerticalAlignment="Top" Width="27" TextChanged="printShiftBox1_TextChanged" />
        <TextBlock Height="25" HorizontalAlignment="Left" Margin="354,301,0,0" Name="textBlock17" Text="Printday Y/N" VerticalAlignment="Top" Width="92" />
        <TextBox Height="25" HorizontalAlignment="Left" Margin="452,296,0,0" Name="printdayBox1" VerticalAlignment="Top" Width="25" TextChanged="printdayBox1_TextChanged" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="795,301,0,0" Name="receiptBox1" VerticalAlignment="Top" Width="27" TextChanged="receiptBox1_TextChanged" />
        <TextBlock Height="22" HorizontalAlignment="Left" Margin="684,302,0,0" Name="textBlock18" Text="Print Receipt Y/N" VerticalAlignment="Top" Width="105" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="565,406,0,0" Name="textBlock19" Text="Enable stock" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="643,405,0,0" Name="stockBox1" VerticalAlignment="Top" Width="31" TextChanged="stockBox1_TextChanged" />
        <Button Content="Update product" Height="49" HorizontalAlignment="Left" Margin="354,155,0,0" Name="prodUpdateButt3" VerticalAlignment="Top" Width="124" Click="prodUpdateButt3_Click" />
        <TextBlock Height="20" HorizontalAlignment="Left" Margin="493,155,0,0" Name="textBlock20" Text="Update product file" VerticalAlignment="Top" Width="148" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="493,181,0,0" Name="produpdateBox1" VerticalAlignment="Top" Width="148" />
        <Button Content="HELP?" Height="62" HorizontalAlignment="Left" Margin="13,652,0,0" Name="HELP" VerticalAlignment="Top" Width="96" Click="HELP_Click" />
    </Grid>
    <Popup x:Name="helppopup" AllowsTransparency="True" Margin="10,10,0,13" StaysOpen="True" Placement="Left" IsEnabled="True" VerticalAlignment="Top" Width="100" Height="420" >
            <StackPanel>
            <Grid  MinHeight="100" MinWidth="80" Width="80" Background="#E6F2ECEC">
            <ListView Height="200" Margin="10,40,0,0" x:Name="helppop" VerticalAlignment="Top" Width="100" TabIndex="1"  BorderThickness="3" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Help" Width="100" DisplayMemberBinding="{Binding Path=line}" />

                    </GridView>
                </ListView.View>
            </ListView>
            <Button Content="Close" Height="15" HorizontalAlignment="Left" Margin="10,400,0,0" Name="Close" VerticalAlignment="Top" Width="15" Click="Close_Click" />
            </Grid>
            </StackPanel>
    </Popup>

</DockPanel>

`                                            

代码隐藏:

private void HELP_Click(object sender, RoutedEventArgs e)
{
    this.helppopup.IsOpen = true;
    using (StreamReader reader = new StreamReader("c:\\database\\config.txt"))
    {
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            this.helppop.Items.Add(line);
        }

网上的所有研究都表明这应该有效,但它没有,请帮忙。

我正在添加完整的xaml,因为我认为这就是问题所在。感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您需要添加弹出窗口所在的PlacementTarget。 例如

<Popup .... PlacementTarget={Binding ElemtnName=_configframe} />

希望它能解决这个问题