I am new to Windows Phone 8.1. I have to implement "Search" functionality wherein I have to search the text file and update list view in my app. Also I have noticed the searchbox and searchresultspage in windows Store 8.1 apps but it's not available on windows phone 8.1. Any idea how shall I do it?
Update: (added code)
public List<DataArticle> matchedarticles { get; set; }
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
var queryText = e.NavigationParameter as String;
var folders = await MHDataSource.GetFoldersAsync();
foreach(var folder in folders)
{
var art = folder.Articles.Where(
article => article.Title.IndexOf(
queryText,StringComparison.CurrentCultureIgnoreCase) > -1);
matchedarticles = art.ToList();
}
this.defaultViewModel["Results"] = matchedarticles;
}
How can I retrieve the articles and assign it to the list(matchedarticles) based on the querytext??
Related
I am making an app that utilizes bluetooth function such as scanning devices etc. I checked the scan flag and returns true but not showing the discoverable device that I am testing.
I am using Samsung J7 Pro as my app test device and Samsung J7 as the device I want to see in the list of discovered devices.
J7 already set as discoverable and with bluetooth ON.
I based my codes in Monkey.BluetoothLE
Here is what I have:
Declarations
ObservableCollection<BluetoothViewModel> vm = new ObservableCollection<BluetoothViewModel>();
Android.Bluetooth.BluetoothManager _blManager;
Android.Bluetooth.BluetoothManager _blManager;
Robotics.Mobile.Core.Bluetooth.LE.Adapter _bleAdapter;
Functions
public BluetoothPage()
{
InitializeComponent();
lvInfo.ItemsSource = vm;
var appContext = Android.App.Application.Context;
_blManager = (Android.Bluetooth.BluetoothManager)appContext.GetSystemService("bluetooth");
_blAdapter = _blManager.Adapter;
_bleAdapter = new Robotics.Mobile.Core.Bluetooth.LE.Adapter();
_bleAdapter.DeviceDiscovered += _bleAdapter_DeviceDiscovered;
_bleAdapter.ScanTimeoutElapsed += _bleAdapter_ScanTimeoutElapsed;
}
private void btnScanStopBluetooth_Click(object sender, EventArgs e)
{
if (!_bleAdapter.IsScanning)
{
if (!_blAdapter.IsEnabled)
{
_blAdapter.Enable();
DisplayInformation("Turning on bluetooth...");
while (!_blAdapter.IsEnabled)
{
//do nothing until enabled
}
}
vm.Clear();
btnScan.Text = "Stop Scan";
_bleAdapter.StartScanningForDevices();
}
else
{
btnScan.Text = "Start Scan";
_bleAdapter.StopScanningForDevices();
}
}
private void _bleAdapter_DeviceDiscovered(object sender, Robotics.Mobile.Core.Bluetooth.LE.DeviceDiscoveredEventArgs e)
{
count++;
vm.Add(new BluetoothViewModel
{
Name = e.Device.Name,
ID = e.Device.ID.ToString(),
RSSI = e.Device.Rssi.ToString()
});
}
private void _bleAdapter_ScanTimeoutElapsed(object sender, EventArgs e)
{
DisplayInformation("Scan Timeout");
_bleAdapter.StopScanningForDevices();
btnScan.Text = "Start Scan";
}
private void DisplayInformation(string line)
{
lblStatus.Text = line;
}
A listview is bound to "vm" that will display the discovered device.
It does not show anything, and count is always zero but I checked the scan flag using _bleAdapter.IsScanning, it returns true.
EDIT:
I tried other open-source sample programs for Bluetooth such as
xamarin-bluetooth-le (BLE Explorer)
Bluetooth-Xamarin.Forms (DemoBluetooth)
None of them seem to list the device. When I use my built-in bluetooth app under settings, it lists the device. What am I missing here?
Have you granted permission for bluetooth and location?
You have to grant permission in the Manifest/or Settings and depending on the sdk (23+) also asking the user for extra permission.
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/permissions?tabs=windows
I'm trying to display a simple toast, it showed the first the I deployed the app but it doesn't show anymore. I didn't change anything to the code between deployments. It's the basic blank project, except in Mainpage this is the only code
public MainPage()
{
this.InitializeComponent();
}
public static void Notification(string title, string content)
{
// Construct the visuals of the toast
ToastVisual visual = new ToastVisual()
{
TitleText = new ToastText()
{
Text = title
},
BodyTextLine1 = new ToastText()
{
Text = content,
},
};
ToastContent toastContent = new ToastContent()
{
Visual = visual,
};
// And create the toast notification
Windows.Data.Xml.Dom.XmlDocument doc = toastContent.GetXml();
var toast = new ToastNotification(toastContent.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
private void buttonShowToast_Tapped(object sender, TappedRoutedEventArgs e)
{
Notification("a", "b");
}
NuGet package installed:
NotificationExtensions.Win10 (version: 14332.0.2)
This is as simple as it could be, why is it not working? Am I missing some sort of permission?
I figured it out. For some reason Windows 10 disabled the notifications for all apps deployed with Visual Studio. Heading over to "Notifications & Actions" in the settings of the device the permissions were toggled off under "Get notifications from these senders".
Toggling the permissions to "On" for the app solved the issue.
The Microsoft Surface Pro has a gyroscope and accelerometer, Windows 8, and the full .NET framework.
Most articles I find that talk about the motion API point to the Windows Phone 8 API.
What .NET Framework namespaces and classes should I be using to get gyroscope and accelerometer data from?
I just worked based off the documentation - http://msdn.microsoft.com/en-us/library/ie/windows.devices.sensors
using Windows.Devices.Sensors;
private Accelerometer _accelerometer;
private void DoStuffWithAccel()
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading != null)
double xreading = reading.AccelerationX;
... etc.
}
}
Haven't tested it, but it should work for any Windows Store App - If you're trying to make it run as a console/windows forms app, you need to change the targetplatform by:
Right Click your project -> Unload Project
Follow the rest of this https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications
For the surface pro you need to use the Windows 8.1 library, instead of the Windows Phone 8.1 library.
It should be in the same Windows.Devices.Sensors namespace.
using Windows.Devices.Sensors;
...
//if you aren't already doing so, and you want the default sensor
private void Init()
{
_accelerometer = Accelerometer.GetDefault();
_gyrometer = Gyrometer.GetDefault();
}
...
private void DisplayAccelReading(object sender, object args)
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading == null)
return;
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
}
...
private void DisplayGyroReading(object sender, object args)
{
GyrometerReading reading = _gyrometer.GetCurrentReading();
if (reading == null)
return;
ScenarioOutput_AngVelX.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityX);
ScenarioOutput_AngVelY.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityY);
ScenarioOutput_AngVelZ.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityZ);
}
I'm currently developing a metro app in which the user can change current language at runtime and all the custom controls that are loaded must update their text regarding to the new language. Problem is that when I change the language using the following code, the app language changes but it will only update text when I restart my app because the pages and controls that are already rendered are cached.
LocalizationManager.UICulture = new System.Globalization.CultureInfo((string)((ComboBoxItem)e.AddedItems[0]).Tag);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = ((ComboBoxItem)e.AddedItems[0]).Tag as String;
What should I do to force updating text of all custom controls at runtime without restarting my app?
Use this:
var NewLanguage = (string)((ComboBoxItem)e.AddedItems[0]).Tag;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = NewLanguage;
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
//Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceManager.Current.DefaultContext.Reset();
and then reload your Page, using Navigate method:
if (Frame != null)
Frame.Navigate(typeof(MyPage));
In order to respond right away, you would need to reset the context of the resource manager.
For Windows 8.1:
var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
resourceContext.Reset();
You will still need to force your page to redraw itself and thus re-request the resources to get the changes to take place. For Windows 8, you can see https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx
You can change the app's language at runtime with the help of this source code. I took help from this and manipulated my app's language settings page as follows:
In languageSettings.xaml.cs:
public partial class LanguageSettings : PhoneApplicationPage
{
public LanguageSettings()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (ChangeLanguageCombo.Items.Count == 0)
{ ChangeLanguageCombo.Items.Add(LocalizationManager.SupportedLanguages.En);
ChangeLanguageCombo.Items.Add(LocalizationManager.SupportedLanguages.Bn);
}
SelectChoice();
}
private void ButtonSaveLang_OnClick(object sender, RoutedEventArgs e)
{
//Store the Messagebox result in result variable
MessageBoxResult result = MessageBox.Show("App language will be changed. Do you want to continue?", "Apply Changes", MessageBoxButton.OKCancel);
//check if user clicked on ok
if (result == MessageBoxResult.OK)
{
var languageComboBox = ChangeLanguageCombo.SelectedItem;
LocalizationManager.ChangeAppLanguage(languageComboBox.ToString());
//Application.Current.Terminate(); I am commenting out because I don't neede to restart my app anymore.
}
else
{
SelectChoice();
}
}
private void SelectChoice()
{
//Select the saved language
string lang = LocalizationManager.GetCurrentAppLang();
if(lang == "bn-BD")
ChangeLanguageCombo.SelectedItem = ChangeLanguageCombo.Items[1];
else
{
ChangeLanguageCombo.SelectedItem = ChangeLanguageCombo.Items[0];
}
}
}
***Note: Before understanding what I did on LanguageSettings page's code behind, you must implement the codes from the link as stated earlier. And also it may be noted that I am working on windows phone 8
I'd like to display a list of contacts in my app. That is a simple task to do, see this answered SO question.
Yet, I only need to display contacts which have a mobile phone number.
How to achieve this? Is there a way using LINQ?
~Chris
Building on the example from MSDN, you can do something like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
Contacts cons = new Contacts();
//Identify the method that runs after the asynchronous search completes.
cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);
//Start the asynchronous search.
cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}
void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
var myMobilePhoneContacts = new List<Contact>();
foreach (var contact in e.Results)
{
myMobilePhoneContacts.AddRange((from phoneNumber in contact.PhoneNumbers
where phoneNumber.Kind == PhoneNumberKind.Mobile
select contact).Select(cont => (Contact)cont));
}
// do something with the contacts in myMobilePhoneContacts
}