I'm trying to implement a settings page (with XAML and C++), with three radio buttons: "Light", "Dark" and "Use system theme". How do I do Application.RequestedTheme? Thanks!
Based on this document about Application.RequestedTheme, it mentions
The theme can only be set when the app is started, not while it's
running. Attempting to set RequestedTheme while the app is running
throws an exception (NotSupportedException for Microsoft .NET code).
If you give the user an option to pick a theme that's part of app UI,
you must save the setting in the app data and apply it when the app is
restarted.
So you could save the setting of theme in the app data and apply it in the constructorof App when you restart your app. For example:
App.xaml.cpp:
App::App()
{
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
if (value != nullptr)
{
String^ colorS = safe_cast<String^>(value);
// Apply theme choice.
if (colorS == L"Dark") {
App::Current->RequestedTheme = ApplicationTheme::Dark;
}
else {
App::Current->RequestedTheme = ApplicationTheme::Light;
}
}
}
Setting.xaml.cpp:
void AppCX::BlankPage::Light_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
}
void AppCX::BlankPage::Dark_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
}
void AppCX::BlankPage::UseSystemTheme_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
if (uiTheme == Windows::UI::Colors::Black.ToString()) {
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
}
else if (uiTheme == Windows::UI::Colors::White.ToString())
{
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
}
}
Related
I can't save User Setting of ComboBox like the TextBox or CheckBox? How to do that?
This is a simple example using .NET 5.
I created a form with a ComboBox ("comboBox1") and a Button ("bnAdd") to add a user-entered value to the ComboBox.
I added a setting with a name of "ThepphuongWCombo", type "String", and scope "User".
When the form is closed, the data from the ComboBox is saved, and the saved data is loaded when the app is run.
using System;
using System.Text.Json;
using System.Windows.Forms;
namespace SaveComboBoxToJson
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bnAdd_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(comboBox1.Text);
}
private void SaveUserData()
{
var json = JsonSerializer.Serialize(comboBox1.Items);
Properties.Settings.Default.ThepphuongWCombo = json;
Properties.Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
// Show the location of the settings file being used in case you want to inspect it.
//var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
//MessageBox.Show(path);
var cbData = Properties.Settings.Default.ThepphuongWCombo;
if (string.IsNullOrEmpty(cbData))
{
// Add some default values.
comboBox1.Items.Add("CCC");
comboBox1.Items.Add("DDD");
}
else
{
var itms = (object[])JsonSerializer.Deserialize(cbData, typeof(object[]));
comboBox1.Items.AddRange(itms);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SaveUserData();
}
}
}
Hello I'm using Lync SDK 2013, to display number phones from contact in ListBox, and use the Items (phone number) to call this number by my API. So i did a WPF application, that contains just a ListBox, and 2 buttons (Call - Hang up). My apllication is added as custom command in Lync, in RightClick in the contact. and it doesn't have any Lync Controls. So what i want to do is: if i Right Click on the contact, my application launches and gives me the number phone List in the ListBox. I did it with a WPF that contains the controls: ContactSearchInputBox (to search a contact) and ContactSearchResultList and it works very Well, I don't know how to do it without controls.
Any One Can Help Me !!!! :(
You need to read and understand the Lync SDK 2013 Lync Contact documentation.
If you wish to "simulate" the Lync Contact "search" (as per the Client search) then you need to look into the search API.
The other concepts you need to understand is the results returned from all the API are NOT guaranteed to return all the Lync Contact data that asked for.
There is no way with the Lync SDK to "load" all the contact information which is what most people seem to not understand.
The results returned are what the local cache has and no more. To get the all the Lync Contact information you need to understand the ContactSubscription model.
For each Lync Contact that you wish to be notified of field updates (or loads) you "subscribe" to the Lync Contact and then you will be notified via the Contact.ContactInformationChanged event.
So your UI must to able to auto-update the information as the fields get loaded / updated from any initial value returned from any Lync Contact value.
public partial class ChoosePhoneNumber : Window
{
LyncClient lync_client;
Contact contact;
ContactSubscription contact_subscription;
List<ContactInformationType> contact_information_list;
ContactManager contact_manager;
public ChoosePhoneNumber()
{
InitializeComponent();
connect_lync();
get_subscribed_contact(this.contact);
}
}
private void connect_lync()
{
try
{
lync_client = LyncClient.GetClient();
contact_manager = lync_client.ContactManager;
}
catch (ClientNotFoundException)
{
MessageBox.Show("Client is ot running", "Error While GetClient", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void get_subscribed_contact(Contact contact)
{
List<object> contact_phone_numbers_list = new List<object>();
contact_information_list = new List<ContactInformationType>();
contact_information_list.Add(ContactInformationType.ContactEndpoints);
contact_information_list.Add(ContactInformationType.DisplayName);
contact = contact_manager.GetContactByUri("number"); // I put here the number phone of a contact in my list
contact_subscription = LyncClient.GetClient().ContactManager.CreateSubscription();
contact_subscription.AddContact(contact);
contact.ContactInformationChanged += Contact_ContactInformationChanged;
contact_subscription.Subscribe(ContactSubscriptionRefreshRate.High, contact_information_list);
List<object> endpoints = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
var phone_numbers_list = endpoints.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone ||
((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone
|| ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
var name = contact.GetContactInformation(ContactInformationType.DisplayName);
if (phone_numbers_list != null)
{
foreach (var phone_number in phone_numbers_list)
{
contact_phone_numbers_list.Add(((ContactEndpoint)phone_number).DisplayName);
}
conboboxPhoneNumbers.ItemsSource = contact_phone_numbers_list;
}
}
private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
{
var contact = (Contact)sender;
if (e.ChangedContactInformation.Contains(ContactInformationType.ContactEndpoints))
{
update_endpoints(contact);
}
}
private void update_endpoints(Contact contact)
{
if ((lync_client != null) && (lync_client.State == ClientState.SignedIn))
{
ContactEndpoint endpoints = (ContactEndpoint)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
}
}
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; ;
try
{
string argsParam = "Contacts=";
if (e.Args.Length > 1)
{
if (e.Args[2].Contains(argsParam))
{
var contacts_sip_uri = e.Args[2].Split('<', '>')[1];
Params.contacts = contacts_sip_uri;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Reading Startup Arguments Error - " + ex.Message);
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string message = e.Exception.Message;
if (e.Exception.InnerException != null)
{
message += string.Format("{0}Inner Exception: {1}", Environment.NewLine, e.Exception.InnerException.Message);
}
MessageBox.Show(message, "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Params is a public static class that contains just contact as public static string contacts { get; set; }
public static class ParamContact
{
public static string contacts { get; set; }
}
I'm creating a live card app that recieves PNGs from a php script running on my server in response to a request from scanning QR codes. At the moment, I simply replace the image on my Live card with the PNG I recieve from the server, but I would like to recieve and display multiple images from the server with each request.
Is there an approved way to show multiple images on a live card? I was thinking there may be a possiblity of generating a menu full of images that simply closed itself when clicked, but it seems like there might be a better alternative.
This is my code at the moment:
Current Code
import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.LiveCard.PublishMode;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.IBinder;
import android.util.Base64;
import android.widget.RemoteViews;
public class iotSplashScreen extends Service {
private static final String LIVE_CARD_TAG = "iotSplashScreen";
private LiveCard mLiveCard;
private RemoteViews mLiveCardView;
public class iotBinder extends Binder {
public void changeImage(String change) {
try {
byte[] bob = Base64.decode(change, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(bob, 0, bob.length);
if(bitmap != null) {
mLiveCardView.setImageViewBitmap(R.id.image_view_id, bitmap);
mLiveCard.setViews(mLiveCardView);
}
else
{
System.out.println("Daaang, dat bitmap was null doe");
}
}
catch (IllegalArgumentException e)
{
System.out.println("Base64 had an issues: " + e);
System.out.println(change);
}
catch (NullPointerException e)
{
System.out.println("Null Pointer: " + e);
}
}
}
private final iotBinder mBinder = new iotBinder();
#Override
public IBinder onBind(Intent intent) {
return mBinder;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
mLiveCardView = new RemoteViews(getPackageName(), R.layout.iot_splash_screen);
mLiveCard.setViews(mLiveCardView);
// Display the options menu when the live card is tapped.
Intent menuIntent = new Intent(this, LiveCardMenuActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
} else {
mLiveCard.navigate();
}
return START_STICKY;
}
#Override
public void onDestroy() {
if (mLiveCard != null && mLiveCard.isPublished()) {
mLiveCard.unpublish();
mLiveCard = null;
}
super.onDestroy();
}
}
Simply add more ImageViews, either in your layout file (iot_splash_screen) or programmatically.
With the resource IDs of your ImageViews, you can call setImageViewResource on each one.
Make sure that you are setting these images before calling setViews on your Live Card.
I have written code to filter out new XML elements that have been introduced as part of web service enhancements. The transformation seems to work with small XML but as soon as I increase the size its stops working. Using SoapUI, it simply returns a blank response.
Can anyone help? Do i need to alter the code below to handle large XML?
public void Dispose()
{
//clean-up code here.
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
context.PreRequestHandlerExecute += new EventHandler (context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
State state = (State)app.Context.Items["VersionManagerState"];
if (state.ProcessRequest)
{
Stream xslres = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Concat("TestService.VersionManager.",state.Version, ".xslt"));
if (xslres != null)
{
state.Xsl = new XslCompiledTransform();
state.Xsl.Load(XmlReader.Create(xslres));
app.Context.Response.Filter = new OutputFilterStream(state, app.Context.Response.Filter);
}
}
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
State state = new State();
app.Context.Items["VersionManagerState"] = state;
if (app.Context.Request.Url.AbsolutePath.EndsWith(".asmx") && app.Request.RequestType == "POST")
{
state.ProcessRequest = true;
app.Context.Request.Filter = new InputFilterStream(state, app.Context.Request.Filter);
}
}
I'm developìng an app in Vaadin and I've found a problem.
I would like to open a new browser window from the action handler added to a vaadin table, and I don't know how to do that. Is that possible?.
table.addActionHandler(new Handler() {
public void handleAction(Action action, Object sender, Object target) {
if (action == ACTION_OPEN_WINDOW) {
// code to open a new browser window
BrowserWindowOpener opener = new BrowserWindowOpener....
/// is it possible open oit here?
}
}
public Action[] getActions(Object target, Object sender) {
return ACTIONS;
}
});
you still can run JavaScript:
JavaScript.getCurrent().execute("window.open('http://google.com', 'Google', 'height=800,width=600');");