i have a timepicker i am showing time on load adding one hour additional. What i want when user click on any past time it should disable the past time .... here is my code what i am trying but this code is not working
private void MyTimePicker_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == TimePicker.TimeProperty.PropertyName)
{
if (tmpickerfrom.Time < DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1)))
{
tmpickerfrom.Unfocus();
tmpickerfrom.Time = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1));
}
}
}
Related
I am making a windows forms app just to test out my designing skills, but I find that the outline is ugly, so I made my own Minimise and Close buttons, but I'm not sure how to make a pannel that you can drag around. Can anyone help me?
By the way, the code is C#.
Using events we can take the current location when we leftclick (MouseDown) and on MouseMove, we take the current window location minus where we were before and add the distance we've dragged our mouse.
public partial class Form1 : Form
{
private Point windowLocation;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
this.windowLocation = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Refers to the Form location (or whatever you trigger the event on)
this.Location = new Point(
(this.Location.X - windowLocation.X) + e.X,
(this.Location.Y - windowLocation.Y) + e.Y
);
this.Update();
}
}
}
I have a page in Xamarin.Forms in which I have to show PKPaymentButton by using the same PKPaymentButton class which is a child of UIButton in PassKit.
I have written a custom ButtonRenderer and trying to convert the button into PKPayment button.
I got so far that in custom renderer we can change the appearance of a button but can we use something like creating a new button instance in my case PKPaymentButton and replace it with Button.
UPDATE-
I have achieved this by-
public class ApplePayButtonRenderer : Xamarin.Forms.Platform.iOS.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var button = new PKPaymentButton(PKPaymentButtonType.Buy, PKPaymentButtonStyle.Black);
SetNativeControl(button);
}
}
}
Now I am trying to get its click into Xamarin.Forms
You could use Messaging Center to send message when you click the payment Button.
in Custom Renderer
var button = new PKPaymentButton(PKPaymentButtonType.Buy, PKPaymentButtonStyle.Black);
button.TouchUpInside += Button_TouchUpInside;
SetNativeControl(button);
private void Button_TouchUpInside(object sender, EventArgs e)
{
MessagingCenter.Send<Object>(this,"PayButtonClick");
}
in Forms
Add the following code to the constructor of the ContentPage which contains the Payment Button
public xxxPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object>(this, "PayButtonClick",(args)=> {
//do some thing you want
});
}
During my override of OnActivate() in my view-model, I need to call GetView() in order to focus an element. When I do this after I have previously activated my view, it's fine. But when I call this the first activation, it fails.
I was able to get it to work by swapping a few lines in ConductorBaseWithActiveItem.ChangeActiveItem. The original is as follows:
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
ScreenExtensions.TryDeactivate(activeItem, closePrevious);
newItem = EnsureItem(newItem);
if(IsActive)
ScreenExtensions.TryActivate(newItem);
activeItem = newItem;
NotifyOfPropertyChange("ActiveItem");
OnActivationProcessed(activeItem, true);
}
and with my changes:
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
ScreenExtensions.TryDeactivate(activeItem, closePrevious);
newItem = EnsureItem(newItem);
activeItem = newItem;
NotifyOfPropertyChange("ActiveItem");
if (IsActive)
ScreenExtensions.TryActivate(newItem);
OnActivationProcessed(activeItem, true);
}
This seems to work. Notifying that "ActiveItem" changed triggers the code to load and cache the view. Then ScreenExtensions.TryActivate calls my OnActivate override.
Question: I haven't noticed any problems doing this, but I'm curious if anyone knows better than I do what repercussions this change could have?
Thanks!
One thing you could try is overriding Caliburn's OnViewAttached method and trying to focus it there. That being said, in MVVM, focus is more of a View concern, so if possible, that logic should be moved from the ViewModel to the View.
One way you may be able to solve this is by creating an attached behavior (you will need a reference to the Microsoft.Expression.Interactions assembly):
public class FocusWhenVisibleBehavior : Behavior<FrameworkElement>
{
protected override void OnAttached()
{
this.AssociatedObject.Loaded += this.Loaded;
this.AssociatedObject.IsVisibleChanged += this.VisibleChanged;
}
protected override void OnDetaching()
{
this.AssociatedObject.Loaded -= this.Loaded;
this.AssociatedObject.IsVisibleChanged -= this.VisibleChanged;
}
private void Loaded(object sender, RoutedEventArgs e)
{
this.TryFocus();
}
private void VisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
this.TryFocus();
}
private void TryFocus()
{
if (this.AssociatedObject.IsLoaded && this.AssociatedObject.IsVisible)
{
// Focus the control
this.AssociatedObject.Focus();
}
}
}
And that attaching that behavior to whatever control you want to focus:
<Button>
<i:Interaction.Behaviors>
<b:FocusWhenVisibleBehavior/>
</i:Interaction.Behaviors>
</Button>
I have a Wizard control that has multiple steps. Controls that are not visible get removed from the visual tree. I have a ListBox on one page, that binds to an ObservableCollection<T>. When items get added or removed to that ListBoxon one page, the ListBox on another page (with the same ItemsSource), the binding on the other page does not get updated. I hope this explains my problem clearly enough.
How do I get this binding to update when the page gets added to the visual tree again ?
I cannot reproduce your problem. I was able to remove a ListBox from the visual tree, add objects to the ObservableCollection, and when I add it to the visual tree, items are actually updated.
Try working around your problem by setting visibility to Collapsed rather than removing from Visual Tree.
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.listBox1.ItemsSource = o;
this.listBox2.ItemsSource = o;
}
ObservableCollection<int> o = new ObservableCollection<int>();
private void buttonList1_Click(object sender, RoutedEventArgs e)
{
if (this.listBox1.Parent == null)
this.LayoutRoot.Children.Add(this.listBox1);
else
this.LayoutRoot.Children.Remove(this.listBox1);
//this.listBox1.Visibility = this.listBox1.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
private void buttonList2_Click(object sender, RoutedEventArgs e)
{
if (this.listBox2.Parent == null)
this.LayoutRoot.Children.Add(this.listBox2);
else
this.LayoutRoot.Children.Remove(this.listBox2);
//this.listBox2.Visibility = this.listBox2.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
private void ButtonAddMore_Click(object sender, RoutedEventArgs e)
{
o.Add(o.Count);
}
}
I have an ASP.NET ListBox on a page, and as postbacks occur, I change the items in the list. If there are >= 10 items in the list, I set the Rows property = 10. But if there are less than 10 items, I'd like to set the Rows back to whatever the default value is for Rows.
I see from examining the reflected code that the default value is 4, but I'd rather not hard code it to 4 in my code and instead somehow just reset it to the default.
Is there a way to do this?
You can fetch the default value during the page's Init phase. From the documentation:
In this stage of the page's life
cycle, declared server controls on the
page are initialized to their default
state; however, the view state of each
control is not yet populated.
So you can do something like:
private int _defaultRows;
protected void Page_Init(object sender, EventArgs e)
{
_defaultRows = yourListBox.Rows;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (yourListBox.Items.Count >= 10) {
yourListBox.Rows = 10;
} else {
yourListBox.Rows = _defaultRows;
}
}