WPF open new Mahapps window with GlowBrush - border

I would like to open a new MetroWindow (Mahapps) with border glow from C# code. I succeded to do that from xaml with the GlowBrush property, but couldn't achived the same result from C# code.
Here is how I tried:
private void Button_Click(object sender, RoutedEventArgs e)
{
MetroWindow window = new MetroWindow()
{
Title = "XY",
ShowTitleBar = false,
GlowBrush = new SolidColorBrush(Colors.DodgerBlue),
ResizeMode = ResizeMode.CanResize,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
};
window.Show();
}
The window opens borderless without any glowing effect.
Could anyone please help me what I am doing wrong?

Related

Thumb.DragStarted event not working in visual studio 2013

I am trying to make a small music player for windows phone. I have added a slider functionality in the player. The slider works fine as the music plays. But I want to change the media according to how much i drag the slider, but cannot find any relevant event for it. I have tried value changed but it does not help. Also I tried Thumb.Dragstarted event but my visual studio gives an error.. this is the code so far:
XAML:
<Slider AllowDrop="True" x:Name="sld1" Thumb.DragStarted="sld1_DragStarted" HorizontalAlignment="Left" Margin="58,213,0,0" VerticalAlignment="Top" Width="351" ValueChanged="sld1_ValueChanged"/>
<MediaElement x:Name="bleep" Source="abcd.wav" AutoPlay="False" Visibility="Collapsed" MediaEnded="bleep_MediaEnded"/>
C#:
public Page1()
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer_Tick;
timer.Start();
}
private bool userIsDraggingSlider = false;
private void timer_Tick(object sender, EventArgs e)
{
if ((bleep.Source != null) && (bleep.NaturalDuration.HasTimeSpan) && (!userIsDraggingSlider))
{
sld1.Minimum = 0;
sld1.Maximum = bleep.NaturalDuration.TimeSpan.TotalSeconds;
sld1.Value = bleep.Position.TotalSeconds;
}
}
private void sld1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
tm_passed.Text = TimeSpan.FromSeconds(sld1.Value).ToString(#"mm\:ss");
}
private void sld1_DragStarted(object sender, DragStartedEventArgs e)
{
userIsDraggingSlider = true;
}
private void sld1_DragCompleted(object sender, DragCompletedEventArgs e)
{
userIsDraggingSlider = false;
bleep.Position = TimeSpan.FromSeconds(sld1.Value);
}
But since the DragCompleted and DragStarted events are not working I cannot provide the drag functionality to the slider.
What I identified from the Thumb class is that, you can't simply add Thumb.DragStarted="sld1_DragStarted within your Slider. You'll be able to add that kind of event only for Thumb control. Refer the bottom of the article for sample code.

CustomMessageBox doesn't adapt when entering text

I've got a problem with a CustomMessageBox in Windows Phone. Normally when you got a page with several textboxes, then the view gets adapted/scrolled when a textinput starts.
But in a CustomMessageBox it seems no to work. It still adapts/scrolls the mainview, which is now in the background.
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var dialog = new CustomMessageBox()
{
Content = new FeedbackView(),
RightButtonContent = "Cancel",
LeftButtonContent = "Send",
VerticalContentAlignment = VerticalAlignment.Top,
VerticalAlignment = VerticalAlignment.Center,
Background = new SolidColorBrush(Colors.Black),
HorizontalContentAlignment = HorizontalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};
dialog.Show();
}
}
I made a little example: https://onedrive.live.com/redir?resid=6B27FD720F1FB58D!16324&authkey=!AKsq3XzgjQviN8w&ithint=folder%2csln
Does have anyone an idea to get this to work or do you think that I have to do this manually by myself?

datepicker in popup directly open when I click a button?

As described i input a datepicker in my xaml file
when i run the page ,datepicker just show like this:
then I have to tap the datepicker to enter the select page like this :
Now
I need to directly open the fullscreen datepicker select page when I click a button
the address give a way that I can just Navigate to the select page,
but I don't know how ?
I'm the poster.
i find a solution myself
Override DatePicker class with our custom DatePickerCustom class. Create new class "DatePickerCustom.cs"
public class DatePickerCustom : DatePicker
{
public void ClickTemplateButton()
{
Button btn = (GetTemplateChild("DateTimeButton") as Button);
ButtonAutomationPeer peer = new ButtonAutomationPeer(btn);
IInvokeProvider provider = (peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider);
provider.Invoke();
}
}
then in the mainpage.xaml.cs
private DatePickerCustom datePicker;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// create datePicker programmatically
if (this.datePicker == null)
{
this.datePicker = new DatePickerCustom();
this.datePicker.IsTabStop = false;
this.datePicker.MaxHeight = 0;
this.datePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker_ValueChanged);
LayoutRoot.Children.Add(this.datePicker);
}
}
void datePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
{
// now we may use got value from datePicker
TextBlock1.Text = this.datePicker.ValueString;
}
so that when do an action like tap or click, the fullscreen datepicker page will be shown
private void button1_Click(object sender, RoutedEventArgs e)
{
this.datePicker.ClickTemplateButton();
}
ps: timepicker can also do the same thing
ps2:here is the details
#Mario Galván
hope it help u

How to change Background image of button on mouse click, created "Dynamically" ? - Windows Phone

I've created buttons dynamically, now unable to handle events on it, there is no usefull link on internet..
button.MouseEnter += new EventHandler(button_MouseEnter);
button.MouseLeave += new EventHandler(button_MouseLeave);
...
void button_MouseLeave(object sender, EventArgs e)
{
}
void button_MouseEnter(object sender, EventArgs e)
{
}
This code is not working ...
MouseEnter and MouseLeave are respectively triggered when the mouse pointer hovers on and out of an object. The event you're searching for is Click.
Other than that, your code should work:
button.Click += new RoutedEventHandler(button_Click);
void button_Click(object sender, RoutedEventArgs e)
{
// Whatever
}
Try the MouseLeftButtonDown and MouseLeftButtonUp events. Change the image to the new one in MouseLeftButtonDown and change it back with MouseLeftButtonUp.
So simple, just put this code as it is.
button.MouseEnter += new EventHandler(button_MouseEnter);
button.MouseLeave += new EventHandler(button_MouseLeave);
void button_MouseLeave(object sender, EventArgs e)
{
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("/Images/camBlue.png", UriKind.Relative));
Button1.Background = brush;
}
void button_MouseEnter(object sender, EventArgs e)
{
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("/Images/camRed.png", UriKind.Relative));
Button1.Background = brush;
}

Not showing images in JToolBar

JButton btnCalendar = new JButton("Chart",new ImageIcon("new_chart.jpg"));
btnCalendar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Chart clicked");
}
});
jToolBar1.add(btnCalendar);
jToolBar1.addSeparator();
I'm developing a Swing based application in which I want to add JToolBar with images in buttons.But images are not visible in the buttons
I face same problem and I resolved by
use of following code :
ImageIcon newImage= new ImageIcon(getClass().getResource("com/some/package/newItemImage.jpg"));
JButton newButton= new JButton(newImage);
this.add(newButton);