How would I make a checkbox hide the dock icon if it was checked?
I have made a checkbox toggle a menubar item but how would you do it with the dock icon?
Looking for some code to do this.
Thanks!
Update for Swift, use both ways has been presented above (they give the same result):
public class func toggleDockIcon_Way1(showIcon state: Bool) -> Bool {
// Get transform state.
var transformState: ProcessApplicationTransformState
if state {
transformState = ProcessApplicationTransformState(kProcessTransformToForegroundApplication)
}
else {
transformState = ProcessApplicationTransformState(kProcessTransformToUIElementApplication)
}
// Show / hide dock icon.
var psn = ProcessSerialNumber(highLongOfPSN: 0, lowLongOfPSN: UInt32(kCurrentProcess))
let transformStatus: OSStatus = TransformProcessType(&psn, transformState)
return transformStatus == 0
}
public class func toggleDockIcon_Way2(showIcon state: Bool) -> Bool {
var result: Bool
if state {
result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.Regular)
}
else {
result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.Accessory)
}
return result
}
i've use this code:
BOOL iconInDock = [[NSUserDefaults standardUserDefaults] boolForKey:smHideShowIcon];
if (iconInDock) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
// display dock icon
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
ok, it's work for my application if I to set LSUIElement=1 in the Info.plist. That's code works only for show, but how I can hide icon?
(Posting this as an answer because comments don't have code formatting)
QSBApplicationDelegate.m:223-228
BOOL iconInDock = [[NSUserDefaults standardUserDefaults] boolForKey:kQSBIconInDockKey];
if (iconInDock) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
You would want to set up your application as LSUIElement, and then use TransformProcessType to enable the Dock icon. The app will need to be relaunched for the change to take effect. See the Google Quick Search Box project for an example.
Setup your application as an LSUIElement and then call:
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
on launch.
This works for the MAS too.
Related
This Is My IOS IPad Page I want to display dropdown as show in image ,Pleases help me how can I write a code ,
I have use picker for that but the menu item is display on bottom ,How i resolve this issue
Here is a workaround that achieve such "Drop Down" via "control combination".
First, add a UITextField on the view to show the item selected.
UITextField _dropTextField;
UIView _dropDownView;
UIPickerView _pickerView;
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
this.View.BackgroundColor = UIColor.White;
// add textfield
_dropTextField = new UITextField();
_dropTextField.Frame = new CGRect(100, 100, 300, 30);
_dropTextField.BackgroundColor = UIColor.Gray;
this.View.AddSubview(_dropTextField);
// call CreateDropDownView
CreateDropDownView();
}
Second, define a method that create a custom UIView holds a UIPickerView.
// create a custom UIView to show pickView
private void CreateDropDownView()
{
_dropDownView = new UIView(new CGRect(_dropTextField.Frame.X, _dropTextField.Frame.Y,
_dropTextField.Frame.Width, 300));
_dropTextField.Delegate = this;
_pickerView = new UIPickerView();
_pickerView.Frame = new CGRect(_dropTextField.Bounds.X, _dropTextField.Bounds.Y + _dropTextField.Frame.Height, _dropTextField.Frame.Width, 300);
PeopleModel pickerModel = new PeopleModel(_dropTextField, _dropDownView);
_pickerView.Model = pickerModel;
_dropDownView.AddSubview(_pickerView);
}
Then, to show the UIView when TextField focused, you also need to implement interface IUITextFieldDelegate.
// show pickerview
[Export("textFieldShouldBeginEditing:")]
public bool ShouldBeginEditing(UITextField textField)
{
View.AddSubview(_dropDownView);
UIApplication.SharedApplication.KeyWindow.BringSubviewToFront(_pickerView);
return false;
}
As for the PeopleModel in the above code, please refer to "class PeopleModel" in this documentation. Also, you need to override some method in it.
private UITextField dropTextField;
private UIView dropDownView;
public PeopleModel(UITextField dropTextField, UIView dropDownView)
{
this.dropDownView = dropDownView;
this.dropTextField = dropTextField;
}
public override nint GetComponentCount(UIPickerView pickerView)
{
return 1;
}
// ...
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
dropDownView.RemoveFromSuperview();
dropTextField.Text = $"{names[pickerView.SelectedRowInComponent(0)]}";
}
// ...
when i write a listview in xamarin forms this icon is auto added to IOS and this is not present in Android
i tried removing this using custom renderer by rendering viewrenderer but this this view renderer never gets call
here is the code which i used for custom renderering
[assembly: ExportRenderer(typeof(ViewCell),
typeof(StandardViewCellRenderer))]
namespace Sample.iOS.Renderers.RevisedRenderer
{
public class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
switch (item.StyleId)
{
case "none":
cell.Accessory = UIKit.UITableViewCellAccessory.None;
break;
case "checkmark":
cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
break;
case "detail-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailButton;
break;
case "detail-disclosure-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailDisclosureButton;
break;
case "disclosure":
default:
cell.Accessory =
UIKit.UITableViewCellAccessory.DisclosureIndicator;
break;
}
return cell;
}
}
}
let me know what need to be modified or add to make it work
remove your switch, and leave the code like this:
var cell = base.GetCell (item, reusableCell, tv);
cell .Accessory = UITableViewCellAccessory.DisclosureIndicator;
You can get more details at:
https://forums.xamarin.com/discussion/88286/xamarin-viewcell-how-to-turn-off-right-arrow-meant-for-touch-action
Cause:
i tried removing this using custom renderer by rendering viewrenderer
but this this view renderer never gets call
The view renderer did get call in your project while the code inside Switch statement never executed, because item.StyleId is always null. You can add a breakpoint to check it.
Solution:
If you want to remove the arrow, just set cell.Accessory = UIKit.UITableViewCellAccessory.None; will work.
class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
Console.WriteLine(item.StyleId);
cell.Accessory = UIKit.UITableViewCellAccessory.None;
// switch (item.StyleId)
// {
// case "none":
// cell.Accessory = UIKit.UITableViewCellAccessory.None;
// break;
// case "checkmark":
// cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
// break;
// case "detail-button":
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DetailButton;
// break;
// case "detail-disclosure-button":
// cell.Accessory =
//UIKit.UITableViewCellAccessory.DetailDisclosureButton;
// break;
// case "disclosure":
// default:
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DisclosureIndicator;
// break;
// }
return cell;
}
}
If you want to show cells with different cell.Accessory style, you can create a custom property instead of using StyleId.
I also uploaded a demo here.
The documentation shows this C# snippet:
async void DisplayDeleteFileDialog(){
ContentDialog deleteFileDialog = new ContentDialog{
Title = "Delete file permanently?",
Content = "If you delete this file, you won't be able to recover it. Do you want to delete it?",
PrimaryButtonText = "Delete",
CloseButtonText = "Cancel"
};
ContentDialogResult result = await deleteFileDialog.ShowAsync();
// Delete the file if the user clicked the primary button.
/// Otherwise, do nothing.
if (result == ContentDialogResult.Primary) {
// Delete the file.
}
else {
// The user clicked the CLoseButton, pressed ESC, Gamepad B, or the system back button.
// Do nothing.
}
}
What I'm requesting is a C++/winRT version of this snippet.
IAsyncAction Async()
{
ContentDialog dialog;
dialog.Title(box_value(L"title"));
dialog.Content(box_value(L"content"));
dialog.PrimaryButtonText(L"primary");
dialog.CloseButtonText(L"close");
auto result = co_await dialog.ShowAsync();
if (result == ContentDialogResult::Primary)
{
}
}
I wanted to open content dialog on button click so I tried the code snippet provided by Kenny Kerr. Everything seemed to work fine without error but when i clicked the button no dialog was seen. i fixed it by placing below code
dialog.XamlRoot(myButton().XamlRoot());
Before auto result = co_await dialog.ShowAsync() line.
ContentDialog.xaml, xaml.h, xaml.cpp should not have the name or classes
named Windows::UI::Xaml::Controls::ContentDialog!!! My name is
ContentDialog1
DirectXPage.xaml.cpp
void YourNamespace::DirectXPage::UpdateStatus(String^ strMessage,
NotifyType type)
{
switch (type)
{
case NotifyType::StatusMessage:
StatusBorder->Background = ref new
SolidColorBrush(Windows::UI::Colors::Green);
break;
case NotifyType::ErrorMessage:
StatusBorder->Background = ref new
SolidColorBrush(Windows::UI::Colors::Red);
break;
default:
break;
}
StatusBlock->Text = strMessage;
// Collapse the StatusBlock if it has no text to conserve real estate.
if (StatusBlock->Text != "")
{
StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Visible;
StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
else
{
StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
// Raise an event if necessary to enable a screen reader to announce
the status update.
auto peer = dynamic_cast<FrameworkElementAutomationPeer^>
(FrameworkElementAutomationPeer::FromElement(StatusBlock));
if (peer != nullptr)
{
peer->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged);
}
}
void YourNameSpace::DirectXPage::NotifyUser(Platform::String^ strMessage,
NotifyType type)
{
if (Dispatcher->HasThreadAccess)
{
UpdateStatus(strMessage, type);
}
else
{
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new
DispatchedHandler([strMessage, type, this]()
{
UpdateStatus(strMessage, type);
ContentDialog1^ dlg = ref new ContentDialog1();
dlg->ContentDialog_SetTitle(L"Error Message");
dlg->ContentDialog_SetTextBlock(L"All textures must be chosen from
the x64\\Release or Debug\\YourNamespace\\AppX\\Assets\\
(Folder or sub-Folders)");
Windows::Foundation::IAsyncOperation<ContentDialogResult>^ result =
dlg->ShowAsync();
if (result->GetResults() == ContentDialogResult::Primary) {}
if (result->GetResults() == ContentDialogResult::Secondary) {}
}));
}
}
I want to tableview accessory button like selectall or deselectall.
cell.Accessory = UITableViewCellAccessory.None;
I want to a button example :"select all"
When user touch this button everycell's accessory should checkmark.
Or I want "Reset" button. if user touch this button every checkmark disappear and Cell's accesory shoul none.
As you have likely found out using UITableView is a bit complicated. However there's a wonderful library available for MonoTouch called MonoTouch.Dialog that makes things a lot easier.
The following sample code is using MonoTouch.Dialog to answer your question (as much as I understand it, let me know if my answer does not match what you wanted).
UIBarButtonItem [] selection_buttons;
void Process (IList<Element> list, bool value)
{
foreach (Element e in list) {
CheckboxElement cb = e as CheckboxElement;
if (cb == null)
continue;
cb.Value = value;
cb.GetImmediateRootElement ().Reload (cb, UITableViewRowAnimation.None);
}
}
void Test ()
{
Section s = new Section ("Select items");
for (int i = 0; i < 10; i++)
s.Add (new CheckboxElement (i.ToString ()));
var root = new RootElement (String.Empty);
root.Add (s);
var dv = new DialogViewController (root, true);
// keep buttons in a field, not a local variable, to ensure it won't be GC'ed away
if (selection_buttons == null) {
selection_buttons = new UIBarButtonItem [] {
new UIBarButtonItem ("Deselect All", UIBarButtonItemStyle.Plain, delegate {
Process (s.Elements, false);
}),
new UIBarButtonItem ("Select All", UIBarButtonItemStyle.Plain, delegate {
Process (s.Elements, true);
})
};
}
dv.NavigationItem.SetRightBarButtonItems (selection_buttons, true);
NavigationController.PushViewController (dv, true);
}
Have fun with MonoTouch (and MonoTouch.Dialog)!
You can checkout this demo from developer.apple.com. Hope it help you.
How can I get events when the Dock is showing or hiding?
You can get a notification if the dock is visible or not using Carbon. I do not know of any way to do it in Cocoa.
(I haven't tested this; it's from the code here)
Create your callback method:
#import <Carbon/Carbon.h>
static const EventTypeSpec appEvents[] = {
{ kEventClassApplication, kEventAppSystemUIModeChanged }
};
OSStatus DockChangedHandler(EventHandlerCallRef inCallRef, EventRef event, void *userData) {
OSStatus status = eventNotHandledErr;
switch(GetEventClass(event)) {
case kEventClassApplication: {
SystemUIMode *outMode;
SystemUIOptions *outOptions;
GetSystemUIMode(outMode, outOptions);
status = noErr;
}
break;
default:
return;
}
/*Insert whatever you want to do when you're notified of a dock change*/
return status;
}
And then put this wherever you want to start listening for the notification:
InstallApplicationEventHandler(NewEventHandlerUPP(DockChangedHandler), GetEventTypeCount(appEvents), appEvents, 0, NULL);
Further information: http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html