How to add or remove array item in windows phone? - c#-4.0

Hi am using xaml file and code given below. I want to get two categories one is current categories and other one is removed categories.If i remove one category it should go to add current category.I don't have any idea about this.so please can any one tell me how to resolve this issue.
<StackPanel>
<TextBlock Text="Current categories"
Style="{StaticResource PhoneTextLargeStyle}"/>
<ListBox x:Name="AddingList" ItemsSource="{Binding name}" SelectionChanged="AddingList_SelectionChanged_1"/>
<TextBlock Text="Removed categories"
Style="{StaticResource PhoneTextLargeStyle}" />
<ListBox x:Name="RemoveList" ItemsSource="{Binding name}" SelectionChanged="RemoveList_SelectionChanged_1"/>
</StackPanel>
my xaml.cs code
private void Button_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/CategoriesPage.xaml?" + NotchsList11, UriKind.Relative));
}
I am using edit button, How can i pass listbox item from edit button to categories page and how remove and add listbox items.
My out put want given below image so please help me some one

Few ways of going about this.
One way is to have a single object that has "isRemoved" boolean on it that you just turn on and off. Another way is you could have 2 observablecollections one holding the added, and one holding the removed. so for example:
class:
public class MyData
{
public bool isRemoved { get; set; }
public string Name { get; set; }
}
Use:
ObservableCollection<MyData> AllData = new ObservableCollection<MyData>()
AllData.Add(new MyData(){ isRemoved = true, Name = "Data1"}
AllData.Add(new MyData(){ isRemoved = true, Name = "Data2"}
AllData.Add(new MyData(){ isRemoved = false, Name = "Data3"}
AddingList.ItemsSource = AllData.Where(srch => srch.isRemoved == false);
RemoveList.ItemsSource = AllData.Where(srch => srch.isRemoved == true);
In your Remove button click you just set the isRemoved to true and in your Add you set the isRemoved to false.
or you could use 2 ObservableCollections adding and removing from each.

Related

UWP AutoSuggestionBox Search Utility using my Model

I'm Currently Working on a Project Designing a Media Player with a Library Ill post the Code for that Method, What i'm trying to Achieve is using the AutoSuggestionBox To Search through my library GridView items then Querying one of the Songs and highlighting it in the GridView
Here's my Code for the Library
private ObservableCollection<MusicLib> MusicList = new ObservableCollection<MusicLib>();
private StackPanel CurrentTarget;
private string content;
public Browsing()
{
this.InitializeComponent();
}
private async void btn_Add_Click(object sender, RoutedEventArgs e)
{
//Create a new picker
var filePicker = new Windows.Storage.Pickers.FileOpenPicker();
//Add filetype filters.
filePicker.FileTypeFilter.Add(".mp3");
filePicker.FileTypeFilter.Add(".wav");
//Set picker start location to the video library
filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
var files = await filePicker.PickMultipleFilesAsync();
foreach (var file in files)
{
StorageItemThumbnail currentThumb = await file.GetThumbnailAsync(ThumbnailMode.MusicView, 200, ThumbnailOptions.UseCurrentScale);
var albumCover = new BitmapImage();
albumCover.SetSource(currentThumb);
var musicProperties = await file.Properties.GetMusicPropertiesAsync();
var musicname = musicProperties.Title;
var musicdur = musicProperties.Duration;
var artist = musicProperties.Artist;
if (artist == "")
{
artist = "Unkown";
}
var album = musicProperties.Album;
if (album == "")
{
album = "Unkown";
}
MusicList.Add(new MusicLib
{
FileName = musicname,
Artist = artist,
Album = album,
Duration = musicdur,
AlbumCover = albumCover,
MusicPath = file.Path
});
}
}
Here's my Context Menu for Deleting Tracks(It's a Work in Progress i'm Probaly missing something stupid)
private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
GridView listView = (GridView)sender;
allContactsMenuFlyout.ShowAt(listView, e.GetPosition(listView));
var a = ((FrameworkElement)e.OriginalSource).DataContext as MusicList;
content = a.text;
}
private void Remove_Click(object sender, RoutedEventArgs e)
{
foreach (var item in MusicList.ToList())
{
if (item.text == content)
{
MusicList.Remove(item);
}
}
content = "";
}
Xaml
<Grid Background="White" Name="MyGrid">
<AutoSuggestBox Name="Search" />
<GridView RightTapped="ListView_RightTapped" Name="mylist" ItemsSource="{x:Bind MusicList}" Margin="0,37,0,0">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Name="Stacky" PointerEntered="myList_PointerEntered" Orientation="Horizontal">
<Image MaxWidth="100" MaxHeight="100" Source="{Binding AlbumCover}"/>
</StackPanel>
<StackPanel >
<TextBlock Text="{Binding FileName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Artist}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Album}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Duration}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FileName}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.Resources>
<MenuFlyout x:Name="allContactsMenuFlyout">
<MenuFlyout.Items>
<MenuFlyoutItem x:Name="Edit" Text="Edit" />
<MenuFlyoutItem x:Name="Remove" Text="Remove" Click="Remove_Click" />
</MenuFlyout.Items>
</MenuFlyout>
</GridView.Resources>
</GridView>
Model
namespace Mp3Player
{
class MusicLib
{
public string FileName { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public TimeSpan Duration { get; set; }
public string MusicPath { get; set; }
public BitmapImage AlbumCover { get; set; }
}
}
To be more specific on my Question im trying to Query one the object's from my Model to "find" that specific track so like FileName For example
I know with the Auto Suggestion box there are 3 Methods you need to use one of which is a Query Method I'm just at a loss as to what to do so if someone could provide a Example possibly, I Will appreciate it, And Post my Project on GitHub for future Ref for anyone who's new to this like i am .
AutoSuggestBox has been documented with detail of its design and how to use it along with its code examples here.
This is a typical AutoSuggestBox
<AutoSuggestBox PlaceholderText="Search" QueryIcon="Find" Width="200"
TextChanged="AutoSuggestBox_TextChanged"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
Backend
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
// Only get results when it was a user typing,
// otherwise assume the value got filled in by TextMemberPath
// or the handler for SuggestionChosen.
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
//Set the ItemsSource to be your filtered dataset
//sender.ItemsSource = dataset;// Here you will filter your music list and only send back the data which matches with the text in your autosuggest box.
}
}
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
// Set sender.Text. You can use args.SelectedItem to build your text string.
}
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args.ChosenSuggestion != null)
{
// User selected an item from the suggestion list, take an action on it here.
}
else
{
// Use args.QueryText to determine what to do.
}
}
In your case you have the collection of MusicLib objects and you need to filter with FileName so the DataSet you send back as filtered data will be from your collection. for that you can use LINQ or just a simple foreach loop if you prefer that.
Note that when you keep filtering your collection but if you change the collection for filtering then you need to keep a second collection as well which will always have all the music tracks,and once you are comfortable with basic concepts, dont hesitate to explore : AdvancedCollectionView by WindowsCommunityToolkit which makes filtering much simpler and powerful for you.
GoodLuck

multiple selection on custom picker C# UWP

I've been looking on forums and internet about a custom picker on C#, I have a picker already functional, but some of my research throw me that you are only able to select 1 item of the custom Picker, this is the code im using to deploy the picker.
Picker
<custom:CustomPicker x:Name="pickerCategories" ItemsSource="{Binding listCategoriesName}" SelectedIndex="{Binding SelectedCategory}" SelectedIndexChanged="pickerCategories_SelectedIndexChanged" Grid.Column="1" BackgroundColor="White"/>
the item source are given to the picker as a list of object from a database
is there a way to be able to select multiple index of the custom picker?
for Example...
Picker pk = new Picker(); pk.SelectionMode=Multiple;
For you requirement, you could make a custom Picker renderer in the native uwp project. And then make a new DataTemplate for displaying ComboBox item that contain checkbox in the native control.
<DataTemplate x:Key="templateEmployee" >
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Content,Mode=TwoWay}" IsChecked="{Binding IsCheck,Mode=TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</StackPanel>
</DataTemplate>
For CustomPickerRenderer, you should pass the Forms Picker item source to native control(ComboBox). And when combobox drop down closed, you could execute InvokeAction method to send Data to the Forms Picker.
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
Control.ItemsSource = e.NewElement.ItemsSource;
Control.ItemTemplate = (Windows.UI.Xaml.DataTemplate)App.Current.Resources["templateEmployee"];
Control.DropDownClosed += Control_DropDownClosed;
}
private void Control_DropDownClosed(object sender, object e)
{
var NewElement = Element as CustomPicker;
var items = (sender as ComboBox).ItemsSource;
NewElement.InvokeAction(items);
}
}
Usage
public MainPage()
{
InitializeComponent();
MyPicker.ItemsSource = new MainViewModel().itemSource;
MyPicker.RegisterAction(IsCheckItems);
}
private List<Item> SelecItms = new List<Item>();
private void IsCheckItems(object data)
{
var items = data as ObservableCollection<Item>;
var str = new StringBuilder();
foreach (var item in items)
{
if (item.IsCheck)
{
SelecItms.Add(item);
str.AppendLine(item.Content);
}
}
SeleitemLabel.Text = str.ToString();
}
And I have uploaded the code sample. Please check.

How to display product availability in Opportunity Products Grid footer?

In Sales Order documents grid footer. It displays the product's availability.
How to do the same in Opportunity products grid ?
More so, how do you enforce it to be displayed at the footer
instead of a simple grid column ? Is there such attribute ?
Thanks for the replies.
If we compare to sales order, the sales order line gets its value from LSSOLine during Availabilty_FieldSelecting. The wire-up on the page is on the tab via StatusField="Availability". We can do something similar by adding an unbound extension field and then during a field selecting fill in the value. An alternative would be to implement an LSCROpportunityProducts class that is inherits LSSelect similar to LSSoLine (a better preferred solution). To keep this simple and focus on just getting the field to display text, I will use an extension field and a simple field selecting in the extension graph for opportunity.
(1) In a dac extension, create an unbound field (MyAvailability is the example field):
[PXTable(typeof(CROpportunityProducts.cROpportunityID), typeof(CROpportunityProducts.cROpportunityProductID), IsOptional = true)]
[Serializable]
public class CROpportunityProductsMyExtension : PXCacheExtension<CROpportunityProducts>
{
#region MyAvailability
public abstract class myAvailability : PX.Data.IBqlField
{
}
protected string _MyAvailability;
[PXString(IsUnicode = true)]
[PXUIField(DisplayName = "Product Availability", Enabled = false)]
public virtual string MyAvailability
{
get
{
return this._MyAvailability;
}
set
{
this._MyAvailability = value;
}
}
#endregion
}
(2) On the opportunity products tab, wire up the new field as the grid status value by setting property StatusField. The page needs modified to add this value and should look something like this when added (requires screen customization in your project -> actions edit ASPX and locate ProductsGrid to paste in your StatusField and value):
<px:PXGrid ID="ProductsGrid" SkinID="Details" runat="server" Width="100%"
Height="500px" DataSourceID="ds" ActionsPosition="Top" BorderWidth="0px"
SyncPosition="true" StatusField="MyAvailability">
(3) Now in a graph extension populate the field:
Edit: The use of Current<> does not always contain the correct currently highlighted row in the UI. Switched to Required<> based on the PXFieldSelectingEventArgs.Row and the results are correct for multiple rows in the products tab.
public class CROpportunityMaintMyExtension : PXGraphExtension<OpportunityMaint>
{
public virtual void CROpportunityProducts_MyAvailability_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
var row = (CROpportunityProducts) e.Row;
if (row == null)
{
e.ReturnValue = string.Empty;
return;
}
INLocationStatus locationStatus = PXSelectGroupBy<INLocationStatus,
Where<INLocationStatus.inventoryID, Equal<Required<CROpportunityProducts.inventoryID>>,
And2<Where<INLocationStatus.subItemID, Equal<Required<CROpportunityProducts.subItemID>>,
Or<Not<FeatureInstalled<PX.Objects.CS.FeaturesSet.subItem>>>>,
And<Where<INLocationStatus.siteID, Equal<Required<CROpportunityProducts.siteID>>,
Or<Required<CROpportunityProducts.siteID>, IsNull>>>>>,
Aggregate<Sum<INLocationStatus.qtyOnHand, Sum<INLocationStatus.qtyAvail>>>
>.Select(sender.Graph, row.InventoryID, row.SubItemID, row.SiteID, row.SiteID);
// Need to convert to transaction UOM... (this is always base units)
decimal? qtyOnHand = locationStatus?.QtyOnHand;
decimal? qtyAvail = locationStatus?.QtyAvail;
e.ReturnValue = $"Qty On hand = {qtyOnHand.GetValueOrDefault()} ; Qty Avail = {qtyAvail.GetValueOrDefault()}";
}
}
The results:

Silverlight User Control Issue

I am trying to create a Repeater Template User Control i.e. a rectangular border contains a row of UIElements Like TextBox, ComboBox etc and then I'm automatically adding a + button at the end of the Row. On + button Click I want to add the Same duplicate row below it.
This is the Syntax making use of User Control:
<RepeaterTemplate>
<RepeaterTemplateItem>
<TextBox />
<ComboBox />
</RepeaterTemplateItem>
</RepeaterTemplate>
CODE BEHIND:
RepeaterLayoutItem:
Public Grid RepeaterRow { get; set; }
Public List LayoutItemCollection { get; set; }
//On + button click handler:
RepeaterLayoutItem duplicate = this.memberWiseClone();
LayoutItemCollection.Add(duplicate);
RepeaterLayout :
public ObservableCollection Children { get; set; }
public Grid RepeaterContentGrid { get; set; }
foreach(RepeaterLayoutItem item in Children)
{
Grid duplicateRow = item.RepeaterRow;
RepeaterContentGrid.Children.Add(duplicateRow); //Here it gives error "Element is already child of other element" on + button click.
}
I also tried it with ICloneable interface, but still same issue.
If I duplicate the row using the memberWiseClone(), still on adding the duplicate row I'm getting the same error. May be bceause of non-null value of Parent property in the cloned duplicate row.
I don't know how to get this functionality working. Please HELP.
Thanks,
GK Prajapati

to show a set of value in list box

I am new to windows phone 8 development. I have a set of value in sqlite database. Now want to show all the value in list view.
C#code
Database database = new Database(ApplicationData.Current.LocalFolder, "people.db");
await database.OpenAsync();
string query = "SELECT * FROM PEOPLE";
Statement statement = await database.PrepareStatementAsync(query);
statement.EnableColumnsProperty();
while (await statement.StepAsync())
{
MessageBox.Show(statement.Columns["Name"] );
txt1.Text = statement.Columns["Name"];
}
xaml code:
<ListBox Margin="0,365,0,0" x:Name="mylist1">
<ListBoxItem Height="190">
<TextBlock Width="443" Height="55" x:Name="txt1"></TextBlock>
</ListBoxItem>
</ListBox>
I show the value in message box. but I want to show the value in list view
this method you will going to need in your future code because sometimes you can not access control from thr name because they can be present in data templates..
first make a observablecollection/list of your messages strings and add your strings/texts in it. like this..
public ObservableCollection<string> MessageList { get; set; }
now add value this collection like this..
MessageList = new ObservableCollection<string>();
MessageList.Add(statement.Columns["Name"];);
MessageList.Add(statement.Columns["Name"];);
MessageList.Add(statement.Columns["Name"];);
MessageList.Add(statement.Columns["Name"];);
MessageList.Add(statement.Columns["Name"];);
now in your class contructor set the datacontext of the page..like this.
public AllMessages()
{
this.DataContext = this;
}
now bind set your listbox itemssource in xaml like this..
<ListBox Margin="0,365,0,0" x:Name="mylist1" ItemsSource="{Binding MessageList}">
<ListBoxItem Height="190">
<TextBlock Width="443" Height="55" x:Name="txt1" Text="{Binding}"></TextBlock>
</ListBoxItem>
</ListBox>
You just need to add items too the listbox.
while (await statement.StepAsync())
{
mylist1.Items.Add(statement.Columns["Name"]);
}

Resources