β [wpf] how to solve autometically closed new window when I create new window..
In StickyNotesView.xaml , I create new Window but If I click '+' that new window not only undisplayed but also programm app is closed too . why?
I just fixed my xaml code
<Grid IsHitTestVisible="True" >
<TextBox Name="SubTextBox" IsHitTestVisible="True" TextChanged="TextBox_Changed"></TextBox>
</Grid>
if I remve <Grid> </Grid> and just reamin TextBox, then the problem is solved. but I wanna add button. so I should use Grid this panel.
First Image is that removed Grid. so new window is displayed. but If i use upper <Grid> </Grid> then New Window is not displayed and program down.
I did dbug but when dbug , that new window is displayed.,... it is weird.
32 Replies
this is my xaml code for creating new window's content like textBox, button.
First of all: $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/Second, if everything closes out of nowhere, then it seems like your App crashed
Can you paste the code that executes after pressing the + Button?
First of all I got it error msg
.
OK I try it
$codegif
This might make it clearer π
BlazeBin - idfkcjivtipf
A tool for sharing your source code with the world!
Problem is that StickyNotesView.xaml and cs file
So your SubTextBox is already part of a StickyNotesView (as seen in StickyNotesView.xaml)
You cant have a control that is child of two different Windows / Controls
I suppose you want to create another textbox in that newly created window
the control you saying is what? Actully first I made Control wpf page named StickyNotesView.xaml but later I changed Control to Window by writing Window in xaml and cs
You see that TextBox there? That's in your StickyNotesView
yes
What's also in your StickyNotesView is this
And there,
newWindow()
is called.
at this point we know that we have a Window that contains a textbox with the name "SubTextBox"yes
Now what happens in
newWindow()
? Exactly what I pointed out earlier: Since SubTextBox
is already part of the Window we are currently at, it cannot be made the child of another Window
But this is what you tried with this line of code win.Content = SubTextBox;
so win.Content = SubTextBox is that issue right?
Yes. That's what Visual Studio pointed out as well π
and this is point right?
Pardon?
You said " You cant have a control that is child of two different Windows / Controls "
so it is point in my code issue
I think i dont understand what you mean with "it is point" π
Ah , I said main point (important point in this issue)
like heart in human , An important issue for resolution. anyway thanks ! I try dbug !
But
when I remove Grid panel, then it is work well
eventhough I didn't fix problem that you point out
before
I understood and resolved it ! I thought present window's item can use other window if that other window created in the same file like StickyNotesView.xaml.cs, however I wrong, thanks to you
Nice one