First i create a tile with this code:
private void btnIconicTile_Click(object sender, RoutedEventArgs e)
{
IconicTileData oIcontile = new IconicTileData();
oIcontile.Title = "Hello Iconic Tile!!";
oIcontile.Count = 7;
oIcontile.IconImage = new Uri("Assets/Tiles/Iconic/202x202.png", UriKind.Relative);
oIcontile.SmallIconImage = new Uri("Assets/Tiles/Iconic/110x110.png", UriKind.Relative);
oIcontile.WideContent1 = "windows phone 8 Live tile";
oIcontile.WideContent2 = "Icon tile";
oIcontile.WideContent3 = "All about Live tiles By WmDev";
oIcontile.BackgroundColor = System.Windows.Media.Colors.Black;
// find the tile object for the application tile that using "Iconic" contains string in it.
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Iconic".ToString()));
if (TileToFind != null && TileToFind.NavigationUri.ToString().Contains("Iconic"))
{
TileToFind.Delete();
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
else
{
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);//
}
}
Now i want that the created tile in the homescreen links to an app (Uri Scheme?) like this on for ex:
await Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"));
How i can modify the "link" of that recently created tile?
Yes i need too.
Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"))
homescreen
Related
I am working with a shopping cart application. I have developed an application that maintains user shopping carts using cookies. It was working perfectly until I have made some UI changes and now it is not working now I have no clue what I have done wrong because I am maintaining the cookies through c# backend code no interruption with the front end only reading these cookies and passing them into view model to show on cart panel. Here is my code
Startup.cs
app.UseRouting();
app.UseCookiePolicy();
app.UseAuthentication();
Adding Items to Cart
public JsonResult AddToShoppingCart(UserProductVM model)
{
try
{
if (string.IsNullOrEmpty(model.SelectedSize))
return Json(new { status = false, msg = "Please select size to proceed." });
var result = ShoppingCartHelper.GetShoppingCartList(model, _httpContextAccessor);
if (result.Status <= 0)
return Json(new { status = false, msg = result.Message });
Response.Cookies.Delete("ShoppingCart");
Response.Cookies.Append("ShoppingCart", JsonConvert.SerializeObject(result.Data));
return Json(new { status = true, msg = "Success! added to shopping cart." });
}
catch (Exception ex)
{
return Json(new { status = false, msg = ex.Message.ToString() });
}
}
Reading From Cart
public static string GetShoppingCartFromCookies(IHttpContextAccessor _httpContextAccessor)
{
return _httpContextAccessor.HttpContext?.Request?.Cookies["ShoppingCart"]?.ToString();
}
Every Thing was working fine and now nothing works no cookies are added to the cookies list. This is the same code I have also the backup my application and when I run that application cookies are working perfectly but the problem is that it is with the old design I am not using that UI design anymore. This is the same code working in one application but not working with another application with a different UI.
Have you added the IHttpContextAccessor to dependency container ?
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
I have resolved my issue. The problem was basically I was adding base64 image string which was not working. When I comment on this line it worked perfectly no need to change any code.
public static GenericResponseDTO<List<ShoppingCartViewModel>> GetShoppingCartList(UserProductVM model, IHttpContextAccessor _httpContextAccessor)
{
var shoppingcartmodel = new List<ShoppingCartViewModel>();
var cartmodel = new ShoppingCartViewModel
{
RestaurantId = model.RestaurantId,
SubCategoryId = model.SubCategoryId,
RestaurantSubCategoryId = model.RestaurantSubCategoryId,
OrderGuid = Guid.NewGuid(),
Quantity = model.Quantity,
//ItemImage = model.ItemImage,
SelectedSize = model.SelectedSize.Split('-')[0],
SingleItemPrice = Convert.ToDecimal(model.SelectedSize.Split('-')[1]),
SubCategoryName = model.SubCategoryName,
TotalItemPrice = (model.Quantity * Convert.ToDecimal(model.SelectedSize.Split('-')[1]))
};
if (string.IsNullOrEmpty(GetShoppingCartFromCookies(_httpContextAccessor)))
shoppingcartmodel.Add(cartmodel);
else
{
shoppingcartmodel = JsonConvert.DeserializeObject<List<ShoppingCartViewModel>>(GetShoppingCartFromCookies(_httpContextAccessor));
if (shoppingcartmodel.Any(x => x.RestaurantSubCategoryId == model.RestaurantSubCategoryId))
return new GenericResponseDTO<List<ShoppingCartViewModel>> { Data = new List<ShoppingCartViewModel>(), Status = -1, Message = "Item is alreay exists in your cart please remove and add another." };
shoppingcartmodel.Add(cartmodel);
}
return new GenericResponseDTO<List<ShoppingCartViewModel>> { Data = shoppingcartmodel, Status = 1 };
}
I have commented on the ItemImage line and it works like a charm. Maybe it helps someone else problem.
I'm trying to create a database with Xamarin.Android but both on the emulator and on the tablet I do not receive an error but nothing is created, where am I wrong?
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// create variables for our onscreen widgets
var btnCreate = FindViewById<Button>(Resource.Id.btnCreateDB);
// create DB path
var docsFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var pathToDatabase = System.IO.Path.Combine(docsFolder, "db_sqlnet.db");
// disable the single and list buttons until the database has been created
btnSingle.Enabled = btnList.Enabled = false;
// create events for buttons
btnCreate.Click += delegate
{
var result = createDatabase(pathToDatabase);
txtResult.Text = result + "\n";
// if the database was created ok, then enable the list and single buttons
if (result == "Database created")
btnList.Enabled = btnSingle.Enabled = true;
};
private string createDatabase(string path)
{
try
{
var connection = new SQLiteConnection(path);
connection.CreateTable< Entity.Person>();
return "Database created";
}
catch (SQLiteException ex)
{
return ex.Message;
}
}
In you I would use the folder System.Environment.SpecialFolder.Personal instead of System.Environment.SpecialFolder.MyDocuments.
End when you open the connection with new SQLiteConnection(path) try to add SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create as second parameter.
I'm trying to add barcode scanner feature to my xamarin.ios app. I'm developing from visual studio and I've added the Zxing.Net.Mobile component from xamarin components store.
I've implemented it as shown in the samples:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
The problem is that when I tap the scan button, the capture view is shown correctly but if I try to capture a barcode nothing happens and it seems the scanner doesn't recognize any barcode.
Someone has experienced this issue? How can I made it work?
Thanks in advance for your help!
I answered a similar question here. I couldn't get barcodes to scan because the default camera resolution was set too low. The specific implementation for this case would be:
ScanButton.TouchUpInside += async (sender, e) => {
var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
.
.
.
scanner.AutoFocus();
//call scan with options created above
var result = await scanner.Scan(options, true);
HandleScanResult(result);
};
And then the definition for HandleCameraResolutionSelectorDelegate:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}
This question is for Android. StyleIds have been set for images. Per the documentation, these StyleIds should appear as labels in Android. But they do not.
I have verified that the following exists -
Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) =>
{
if (!string.IsNullOrWhiteSpace(e.View.StyleId))
{
e.NativeView.ContentDescription = e.View.StyleId;
}
};
I am new to Xamarin UItests and have to solve this as the first thing. Has anyone encountered this before?
You could switch over to using AutomationId, it was introduced to Xamarin.Forms in version 2.2 (release notes)
The AutomationId property isn't used by Xamarin.Forms so it doesn't affect any functionality to use it as a unique identifier for testing.
Below is a sample using AutomationId on an image, along with a screenshot of a Repl Tree output. (Click here to read more about AutomationId)
public App()
{
// The root page of your application
var content = new ContentPage
{
Title = "XamarinUITest_Images",
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
},
new Image {
Source = "circle1",
StyleId = "myStyleID",
AutomationId = "myAutomationID"
}
}
}
};
MainPage = new NavigationPage(content);
}
Sory for my english. I want attach image from gallery and show in edit text with SpannableStringBuilder. I have success for get Image Path from Gallery. After picture selected, Picture Show. But, for the second attach image picture not show and first image attach became a text. any one give me solution ? big thanks.
this is my code:
private void IntentPict() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select File"),MY_INTENT_CLICK);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
if (requestCode == MY_INTENT_CLICK){
if (null == data) return;
String selectedImagePath;
Uri selectedImageUri = data.getData();
//there is no problem with get path
selectedImagePath = ImageFilePath.getPath(getApplicationContext(), selectedImageUri);
//pathImag is ListArray<String>
pathImg.add(selectedImagePath);
addImageBetweentext(pathImg);
}
}
}
private void addImageBetweentext(ArrayList<String> listPath) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
for(int i=0;i<listPath.size();i++){
String path = listPath.get(i);
Drawable drawable = Drawable.createFromPath(path);
drawable.setBounds(0, 0, 400, 400);
ssb.append(mBodyText+"\n");
ssb.setSpan(new ImageSpan(drawable), ssb.length()-(path.length()+1),
ssb.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
}
Here's something that should work. I am loading resource drawables instead, just because it was quicker for me to validate, but I tried to keep as mich as possible for your original flow and variable names:
Drawable[] drawables = new Drawable[2];
drawables[0] = getResources().getDrawable(R.drawable.img1);
drawables[1] = getResources().getDrawable(R.drawable.img2);
SpannableStringBuilder ssb = new SpannableStringBuilder();
for (int i = 0; i < drawables.length; i++) {
Drawable drawable = drawables[i];
drawable.setBounds(0, 0, 400, 400);
String newStr = drawable.toString() + "\n";
ssb.append(newStr);
ssb.setSpan(
new ImageSpan(drawable),
ssb.length() - newStr.length(),
ssb.length() - "\n".length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
Long story short: the start position for the incremental builder needs to be set to the current length of it, minus what you just added.