Есть 2 окна. 1е - главное, 2е - которое вызывается по нажатию кнопки в главном окне. Необходимо, чтобы при наведении на кнопку в главном окне, всплывало еще одно окошко ( Popup ) и в нем выводилась копия всего, что отображается во втором окне. Грубо говоря как в панели задач в Windows 7 и Vista. Знаю как сделать копию элемента с помощью VisualBrush в коде XAML, но только того элемента, что находится в этом же окне! Вроде так:| Код | <Grid> <Canvas Name="wind"> <Button Content="Button" Name="button1" Margin="69,39,118,26" Click="button1_Click" MouseEnter="button1_MouseEnter" MouseLeave="button1_MouseLeave" /> </Canvas> <Canvas> <Popup> <Rectangle Height="{Binding Path=(Canvas.ActualHeight), ElementName=wind}" Width="{Binding Path=(Canvas.ActualWidth), ElementName=wind}"> <Rectangle.Fill> <VisualBrush Visual="{Binding ElementName=wind}"></VisualBrush> </Rectangle.Fill> </Rectangle> </Popup> </Canvas> </Grid>
|
Кто знает как хотя бы переделать этот код в C#, чтобы оттуда обращаться к элементам любых окно и задавать любое необходилое имя ElementName. Пробовалось делать так: | Код | NameScope.SetNameScope(this, new NameScope());
StackPanel myStackPanel = new StackPanel();
Border myReflectedBorder = new Border(); this.RegisterName("ReflectedVisual", myReflectedBorder);
// Create the object to contain the reflection. Rectangle reflectionRectangle = new Rectangle();
Binding heightBinding = new Binding(); heightBinding.ElementName = "ReflectedVisual"; heightBinding.Path = new PropertyPath(Rectangle.ActualHeightProperty); BindingOperations.SetBinding(reflectionRectangle, Rectangle.HeightProperty, heightBinding);
Binding widthBinding = new Binding(); widthBinding.ElementName = "ReflectedVisual"; widthBinding.Path = new PropertyPath(Rectangle.ActualWidthProperty); BindingOperations.SetBinding(reflectionRectangle, Rectangle.WidthProperty, widthBinding);
VisualBrush myVisualBrush = new VisualBrush(); Binding reflectionBinding = new Binding(); reflectionBinding.ElementName = "ReflectedVisual"; BindingOperations.SetBinding(myVisualBrush, VisualBrush.VisualProperty, reflectionBinding);
reflectionRectangle.Fill = myVisualBrush; myReflectedBorder.Child = btn; // это просто кнопка. в Popup она выводится, а вот копия элемента - нет.
myStackPanel.Children.Add(myReflectedBorder); myStackPanel.Children.Add(reflectionRectangle);
codePopup = new Popup(); codePopup.HorizontalOffset = 800; codePopup.VerticalOffset = 400; codePopup.Height = 450; codePopup.Width = 300;
codePopup.Child = myStackPanel;
codePopup.IsOpen = true;
|
Это сообщение отредактировал(а) f0xic - 23.11.2010, 23:52
|