fixed a bug of Dialog
This commit is contained in:
1 parent
a794c2a2c0
commit
2a89bf42f7
5 files changed
+34
-22
No files matched your search
@@ -9,7 +9,7 @@
|
|||||||
Background="{DynamicResource RegionBrush}"
|
Background="{DynamicResource RegionBrush}"
|
||||||
MinWidth="500"
|
MinWidth="500"
|
||||||
DataContext="{Binding DialogDemo,Source={StaticResource Locator}}">
|
DataContext="{Binding DialogDemo,Source={StaticResource Locator}}">
|
||||||
<AdornerDecorator>
|
<hc:DialogContainer>
|
||||||
<hc:TransitioningContentControl>
|
<hc:TransitioningContentControl>
|
||||||
<hc:SimplePanel>
|
<hc:SimplePanel>
|
||||||
<StackPanel Margin="32" VerticalAlignment="Center">
|
<StackPanel Margin="32" VerticalAlignment="Center">
|
||||||
@@ -22,5 +22,5 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</hc:SimplePanel>
|
</hc:SimplePanel>
|
||||||
</hc:TransitioningContentControl>
|
</hc:TransitioningContentControl>
|
||||||
</AdornerDecorator>
|
</hc:DialogContainer>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
+20
-19
@@ -14,7 +14,7 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
private string _token;
|
private string _token;
|
||||||
|
|
||||||
private Adorner _container;
|
private AdornerContainer _container;
|
||||||
|
|
||||||
private static readonly Dictionary<string, FrameworkElement> ContainerDic = new Dictionary<string, FrameworkElement>();
|
private static readonly Dictionary<string, FrameworkElement> ContainerDic = new Dictionary<string, FrameworkElement>();
|
||||||
|
|
||||||
@@ -107,35 +107,36 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
FrameworkElement element;
|
FrameworkElement element;
|
||||||
|
|
||||||
|
AdornerDecorator decorator;
|
||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
element = WindowHelper.GetActiveWindow();
|
element = WindowHelper.GetActiveWindow();
|
||||||
|
decorator = VisualHelper.GetChild<AdornerDecorator>(element);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ContainerDic.TryGetValue(token, out element);
|
ContainerDic.TryGetValue(token, out element);
|
||||||
|
decorator = element is System.Windows.Window ?
|
||||||
|
VisualHelper.GetChild<AdornerDecorator>(element) :
|
||||||
|
VisualHelper.GetChild<DialogContainer>(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element != null)
|
if (decorator != null)
|
||||||
{
|
{
|
||||||
var decorator = VisualHelper.GetChild<AdornerDecorator>(element);
|
if (decorator.Child != null)
|
||||||
if (decorator != null)
|
|
||||||
{
|
{
|
||||||
if (decorator.Child != null)
|
decorator.Child.IsEnabled = false;
|
||||||
|
}
|
||||||
|
var layer = decorator.AdornerLayer;
|
||||||
|
if (layer != null)
|
||||||
|
{
|
||||||
|
var container = new AdornerContainer(layer)
|
||||||
{
|
{
|
||||||
decorator.Child.IsEnabled = false;
|
Child = dialog
|
||||||
}
|
};
|
||||||
var layer = decorator.AdornerLayer;
|
dialog._container = container;
|
||||||
if (layer != null)
|
dialog.IsClosed = false;
|
||||||
{
|
layer.Add(container);
|
||||||
var container = new AdornerContainer(layer)
|
|
||||||
{
|
|
||||||
Child = dialog
|
|
||||||
};
|
|
||||||
dialog._container = container;
|
|
||||||
dialog.IsClosed = false;
|
|
||||||
layer.Add(container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private void Close(DependencyObject element)
|
private void Close(DependencyObject element)
|
||||||
{
|
{
|
||||||
if (element != null)
|
if (element != null && _container != null)
|
||||||
{
|
{
|
||||||
var decorator = VisualHelper.GetChild<AdornerDecorator>(element);
|
var decorator = VisualHelper.GetChild<AdornerDecorator>(element);
|
||||||
if (decorator != null)
|
if (decorator != null)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Windows.Documents;
|
||||||
|
|
||||||
|
namespace HandyControl.Controls
|
||||||
|
{
|
||||||
|
public class DialogContainer : AdornerDecorator
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\FloatingBlock.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\FloatingBlock.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\CarouselItem.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\CarouselItem.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Dialog\DialogContainer.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\GrowlWindow.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\GrowlWindow.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageBlock.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageBlock.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Input\PinBox.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Input\PinBox.cs" />
|
||||||
@@ -147,7 +148,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\Carousel.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\Carousel.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ChatBubble.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ChatBubble.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\ColorPicker\ColorPicker.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\ColorPicker\ColorPicker.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Dialog.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Dialog\Dialog.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\GotoTop.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\GotoTop.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Gravatar.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Gravatar.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\Growl.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\Growl.cs" />
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ namespace HandyControl.Tools
|
|||||||
|
|
||||||
public static T GetChild<T>(DependencyObject d) where T : DependencyObject
|
public static T GetChild<T>(DependencyObject d) where T : DependencyObject
|
||||||
{
|
{
|
||||||
|
if (d == null) return default;
|
||||||
if (d is T t) return t;
|
if (d is T t) return t;
|
||||||
|
|
||||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
|
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
|
||||||
|
|||||||
Reference in new issue
Block a user