There is a MediaElement in my silverLight4 Application that plays videos.
There are also other controls in the form (listbox, buttons etc...).
When vieweing a Video, i want the option to switch to Fullscreen, but only the video and not all the form (something like youtube), is there a way to switch just the 'MediaElement' control to fullscreen?
Make your MediaElement the RootVisual of the app. Since you can't change the RootVisual once it's assigned you need to do something like so
private MainPage _mainPage = new MainPage();
private MediaElement _media = new MediaElement();
private void Application_Startup(object sender, StartupEventArgs e)
{
Grid grid = new Grid();
grid.Children.Add(_mainPage);
this.RootVisual = grid;
}
public void FullscreenVideo()
{
(this.RootVisual as Grid).Children.Clear();
(this.RootVisual as Grid).Children.Add(_media);
Application.Current.Host.Content.IsFullScreen = true;
}
If you call FullscreenVideo it should load your MediaElement into a fullscreen window
Related
i want to show contents of window in wpf when click on button
i think will use container controls like stake panel but doesn't work
private void RibbonButton_Click(object sender, RoutedEventArgs e)
{
Window1 w1 = new Window1();
stkShow.Children.Add(w1);
}
You need to use the content of the window you want to use as child.
This worked for me.
private void RibbonButton_Click(object sender, RoutedEventArgs e)
{
Window1 Child = new Window1();
StkPanelContent.Children.Clear();
object content = Child.Content;
Child.Content = null;
Child.Close();
this.stkShow.Children.Add(content as UIElement);
}
I hope it helps.
I have an application where I have to bind a Data Grid witch is on an User control in a Tab Item.
This process take a while so I create another Tab Item with a Loading animation in a separate thread and when I load data in data grid I select the tab item with the animation until the data is loaded.
The problem is that the animation is starting, but when the data grid binding starts, the animation is freezing.
this.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(
delegate()
{
tiLoading.Content = new Controls.Loading.LoadingAnimation();
tiLoading.IsSelected = true;
}
));
//And now I populate the content of the Tab Item with the User Control that contains data grid
connType = choseConnType(); // Here is a dialog witch ask the user somethig and return a value
tiGeneral.Content = new Windows.General(true, connType);
After the dialog when starts the binding the LoadingAnimation is freezing.
It's understandable. If you have long-running process you should be using BackgroundWorker to run it.
public void ItsGonnaBeLong()
{
this.IsBusy = true;
var worker = new BackgroundWorker();
worker.DoWork += this.MyDoWorkMethod;
worker.RunWorkerCompleted += this.MyDoWorkCompleted;
worker.RunWorkerAsync();
}
private void MyDoWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// executed after work on background thread is completed
this.IsBusy = false;
}
private void MyDoWorkMethod(object sender, DoWorkEventArgs e)
{
// Do something.
}
And is it pretty to have your animation on different TabItem? Have you considered using BusyIndicator from Extended WPF Toolkit? You can simply wrap your Control with BusyIndicator and use Its IsBusy property to run it.
<xctk:BusyIndicator IsBusy="True" >
<my:MyUserControl />
</xctk:BusyIndicator>
If the user clicks on the overlay, I want the ChildWindow to automatically close and return the user to the main screen.
Is there a property that controls this? If not, is there a way to attach a click handler to the overlay?
Turns out you can get a reference to the overlay right after it is created. After that it is a simple matter of attaching the event handler.
private void Overlay_MouseButtonDown(object sender, MouseButtonEventArgs e)
{
this.Close();
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var overlay = (Grid)GetTemplateChild("Overlay");
overlay.MouseLeftButtonDown += Overlay_MouseButtonDown;
overlay.MouseRightButtonDown += Overlay_MouseButtonDown;
}
Upon starting up my silverlight app a child window appears to prompt the user to login. Within in the window I have a username textbox that I want to be focused so that the user can begin typing without focusing it with the mouse first.
This seems like it should work:
public partial class LoginForm : ChildWindow
{
public LoginForm()
{
InitializeComponent();
}
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
txtUsername.Focus();
}
}
I noticed that the Load event happens before the window is rendered which might be the problem, however I don't see an event handler for Rendered or similar.
Edit: Forgot to mention this application is running in the browser.
You need set TabIndex on txtUsername with lower value than other controls on that child window.
Try this:
public partial class LoginForm : ChildWindow
{
public LoginForm()
{
InitializeComponent();
Loaded+=LoginFormLoaded;
}
private void LoginFormLoaded(object sender, RoutedEventArgs e)
{
txtUsername.Focus();
Loaded-=LoginFormLoaded;
}
}
update:
You can also add your event on your TextBox. the textbox has a Loaded event too. If you use this event, you are sure that the TextBox is loaded.
If you are running the application in the browser make sure that the silverlight plugin has focus before calling the focus method of the control.
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
HtmlPage.Plugin.Focus();
txtUsername.Focus();
}
This works on most browsers except I couldn't get it to work on Safari.
Here is something I use:
public partial class LoginForm : ChildWindow
{
public LoginForm()
{
InitializeComponent();
Loaded += (s, e) =>
{
txtUsername.Focus();
};
}
}
And in XAML set your TabIndex to 1
For some reason that I do not have time to figure out, the Child Window in the Silverlight SDK opens, animates, and the focus moves to some unknown place. Most of the solutions suggested on this thread do not work for me because the control receives focus briefly (you can see the focus hit the text box) and then the focus moves to somewhere else (I am guessing that the storyboard on the ChildWindow template has something to do with that). So, I figured out this work around that is actual code that has been implemented and has been proven to work:
public NewChildWindow()
{
InitializeComponent();
this.GotFocus += NewChildWindow_GotFocus;
}
private void NewChildWindow_GotFocus(object sender, RoutedEventArgs e)
{
this.GotFocus -= NewChildWindow_GotFocus;
txtBoxToFocusOn.Focus();
}
Make your textbox TabIndex="0" and in its Loaded event do the "YourtxtBox.Focus()"
I have a Silverlight application in which I'm not using XAML. I have a basic application with the following code in Application_Startup:
private void Application_Startup(object sender, StartupEventArgs e)
{
Grid g = new Grid();
g.Children.Add(new Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://sstatic.net/so/img/sprites.png", UriKind.Absolute)) });
this.RootVisual = g;
}
This code will not render the specified image. If however, the App.Xaml file is modified to define the RootVisual in the Xaml the following works:
xaml:
<Application.RootVisual>
<Grid>
</Grid>
</Application.RootVisual>
code:
private void Application_Startup(object sender, StartupEventArgs e)
{
((Grid)this.RootVisual).Children.Add(new Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://sstatic.net/so/img/sprites.png", UriKind.Absolute)) });
}
I don't see why one would work and the other not. I have the same behavior using a UserControl as well (using Content instead of Childern of course).
From what I understand, there should be not XAML requirement. Is there something I'm missing?
The difference is in the first case you are setting the RootVisual to be a Grid, but in the second your grid is a child element.
On the MSDN page for the RootVisual property it shows the following example:
this.RootVisual = new Page();
so if you create a Page and then add your Grid to that page it should work.
Page page = new Page();
page.Content = g;
this.RootVisual = page;