How to Remove this Arrow or Image From IOS Listview in Xamarin forms - xaml

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.

Related

C++/winRT xaml ContentDialog example

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) {}
}));
}
}

gtkmm changing toggle button state without invoking signal

I'm trying to make multiple Gtk::ToggleButton's to act as Gtk::RadioButton's. When one of the buttons is pressed that other switch off.
It would be as simple as creating a switch statement if Gtk::ToggleButton didn't handle switching (pressed or not pressed) on its own.
So, I'm planning to handle it's switching as regular button with calling signal_clicked().connect() which calls for function set_active(true/false) which makes button look pressed or not pressed.
Here is example of what I'm trying to do:
Event calls when button is clicked:
//enum {infoState, artState, editState, userState, exitState}; is initialised in header
artButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), artButt));
editButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), editButt));
Toggling button:
void fooClass::toggleButton()
{
//oldState and enum {infoState, artState, editState, userState, exitState}; are initialised in header
if(oldState != newState)
{
//disable old togglebutton
switch (oldState)
{
case infoState:
infoButt.set_active(false);
break;
case artState:
artButt.set_active(false);
break;
case editState:
editButt.set_active(false);
break;
case userState:
userButt.set_active(false);
break;
}
//enable new one
switch (newState)
{
case infoState:
userButt.set_active(false);
break;
case artState:
artButt.set_active(true);
break;
case editState:
editButt.set_active(true);
break;
case userState:
userButt.set_active(true);
break;
}
oldState = newState;
}
}
Just useGtk::RadioButton directly. With the draw-indicator property you can make them look like regular toggle buttons.
Ok, so here is my workaround. There is probably better way, so please if you know any post it here:
Firstly use Gtk::Button instead of Gtk::ToggleButton .
Secondly instead of set_active() use set_state_flags(). Gtk::STATE_FLAG_CHECKED when you want it to be enabled and GTK::STATE_FLAGS_NORMAL when you want it to be disabled.
So, this is how code should look like:
void Window::changeState()
{
if(oldState != state)
{
//delete old state
switch (oldState)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case editState:
editButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
}
//move to new state
switch (state)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case editState:
head.editButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case exitState:
close();
break;
}
show_all_children();
oldState = state;
}
}

Selective keyPressEvent, filter for its sender QLineEdit

I've created a QWidget, which contains three QLineEdits. Then I added a overwrote the keyPressEvent so that this lineEdit_3 reacts on key press. Working good.
void MySuperWidget::keyPressEvent(QKeyEvent* keyEv)
{
switch (keyEv->key()) {
case Qt::Key_Up:
//.. stuff
break;
case Qt::Key_Down: {
//.. stuff
}
break;
default:
break;
}
}
BUT the first and second QLineEdit also react on keypress :(
I need somethng like this:
if (sender() != ui->lineEdit_3 ) {
keyEv->ignore();
}

How to use CharmFlyoutLibrary with master page?

I have a Windows 8 app, and recently I refactored it to use a 'master page'. This means that there is one 'layout' that has a few generic components such as the header and footer. In that layout, I have a Frame. Every time I want to show a different view, I load it in the frame.
This means that my startup screen is no longer of type Frame but of type Layout, which is a LayoutAwarePage. This is how I initialize it in App.xaml.cs OnLaunched:
Layout rootFrame = Window.Current.Content as Layout;
if (rootFrame == null)
{
rootFrame = new Layout();
Here comes the problem: I have a charms flyout that contains a few items like Settings. I made a nice view (Flayouts.xaml) that contains the layout of these flyouts. The code behind for that view looks like this:
public Flyouts()
{
InitializeComponent();
SettingsPane.GetForCurrentView().CommandsRequested += Flyouts_CommandsRequested;
}
void Flyouts_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
// add some commands
}
And this is how you'd get this to work in your app:
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new CharmFlyoutLibrary.CharmFrame { CharmContent = new Flyouts() };
What they're doing here is assigning a Frame to 'rootFrame'. However, since I switched to a master page, I no longer have a Frame but a Layout/LayoutAwarePage type, so I can't assign the CharmFrame to it. How do I overcome this problem?
Anyone?
When navigating inside a frame the page that you navigate to is placed inside the navigate the Content property.
So if you navigate to you Layout first, then the content will be filled with your page and you can navigate to your child page's. I've placed a example below
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null) {
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
//Associate the frame with a SuspensionManager key
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) {
// Restore the saved session state only when appropriate
try {
await SuspensionManager.RestoreAsync();
} catch (SuspensionManagerException) {
//Something went wrong restoring state.
//Assume there is no state and continue
}
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null) {
if (rootFrame.Navigate(typeof(Layout))) {
var secondFrame = rootFrame.Content as Layout;
if (!secondFrame.ContentFrame.Navigate(typeof(YourPage)) {
throw new Exception("Failed to create initial page");
}
}
}

Making a Checkbox Toggle The Dock Icon On and Off

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.