If condition in webgrid - webgrid

I want to show the image if the item has image, and no image otherwise. Here is my code, but it gets some errors.
So how to use if condition in format parameter of webgrid?
grid.Column("Image", "Ảnh minh họa", format: (item) =>
if(item.Image == null)
{
#<text>Chưa có ảnh minh họa</text>
}
else
{
#<text><img width="50" height="50" src="#Url.Content("~/images/")#item.Image" /></text>
}
, canSort: false)
Edit:
I have solved this issue. Here is my code:
grid.Column("Image", "Ảnh minh họa", format: #<text>#if (item.Image == null) { <text>Chưa có ảnh minh họa</text> } else { <text><img width="50" height="50" src="#Url.Content("~/images/")#item.Image" /></text> }</text>
, canSort: false),

Try like this:
grid.Column("Image", "Ảnh minh họa", format: (item) =>
if((string)item.Image == null)
{
#<text>Chưa có ảnh minh họa</text>
}
else
{
#<text><img width="50" height="50" src="#Url.Content(string.Format("~/images/{0}",(string)item.Image))" /></text>
}
, canSort: false)
Edit
grid.Column("Image", "Ảnh minh họa",
format: item.Image == null
? #<text>Chưa có ảnh minh họa</text> : #<text><img width="50" height="50" src="#Url.Content(string.Format("~/images/{0}",(string)item.Image))" /></text>,
canSort: true)

Related

Why is MenuFlyout.Items always null in Closing event?

I can successfully add a MenuFlyoutItem to a MenuFlyout dynamically in the ContextMenuFlyout_Opening event, but when I try to remove it in ContextMenuFlyout_Closing the MenuFlyout.Items is always null and the MFI isnt found and removed.
Any ideas why this is so?
<Page.Resources>
<MenuFlyout
x:Key="ListViewContextMenu"
Closing="{x:Bind ViewModel.ContextMenuFlyout_Closing}"
Opening="{x:Bind ViewModel.ContextMenuFlyout_Opening}">
<MenuFlyoutItem
Click="{x:Bind ViewModel.EditParty}"
Icon="Edit"
Text="Edit" />
<MenuFlyoutItem Text="Open in new window">
<MenuFlyoutItem.Icon>
<FontIcon
FontFamily="Segoe MDL2 Assets"
FontSize="40"
Glyph="" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem
Click="MenuFlyoutItem_Click"
Icon="Delete"
Text="Delete" />
</MenuFlyout>
</Page.Resources>
ViewModel event handlers
public void ContextMenuFlyout_Opening(object sender, object e)
{
MenuFlyout flyout = sender as MenuFlyout;
if (flyout != null)
{
// If party.IsConflict = true then add the MFI
if (SelectedTalent.IsConflict)
{
flyout.Items.Add(new MenuFlyoutItem()
{
Icon = new FontIcon() { Glyph = "\uEC4F" },
Text = "Resolve Conflict"
});
}
}
}
public void ContextMenuFlyout_Closing(object sender, object e)
{
// Remove 'Resolve Conflict' MFI if its found
MenuFlyout flyout = sender as MenuFlyout;
if (flyout != null)
{
var rc = flyout.Items.FirstOrDefault(o => o.Name == "Resolve Conflict");
if (rc != null)
{
flyout.Items.Remove(rc);
}
}
}
ListView that uses the MenuFlyout
<ListView
ContextFlyout="{StaticResource ListViewContextMenu}"
Based on your code, it seems that you are trying to get the MenuFlyoutItem object by name. But you forget to give the MenuFlyoutItem object a Name when you add it to the MenuFlyout, you just added a Text property.
flyout.Items.Add(new MenuFlyoutItem()
{
Icon = new FontIcon() { Glyph = "\uEC4F" },
Text = "Resolve Conflict",
Name = "Resolve Conflict",
});

Update input value based on another input's value?

In react-admin, there doesn't seem to be any way to access the state of an input, nor to add an onChange prop to an input. We want to be able to have the user select something from, say an AutocompleteInput, and then populate a value in, say, a TextInput. Is this possible? If so, please post a code example.
Here's an example - two TextInput fields (quantity and cost) that, when the user enters these values, automatically populates the third field, amount. When not using react-admin, we can do this:
handleTextInputChange = event => {
let {target} = event;
let source = target.getAttribute('source');
let {record} = this.state;
let {amount} = record;
if( 'cost' === source || 'quantity' === source ){
amount = ( 'cost' === source ? record.quantity*target.value : target.value*record.cost );
}
if( source ){
record[source] = target.value;
if( 'amount' !== source ){
record['amount'] = amount;
}
this.setState({record: record});
}
};
render() {
let {record} = this.state;
return (
<form>
<Grid container spacing={24}>
<Grid item sm={4} xs={12}>
<label>Quantity</label><br />
<TextField
id="quantity"
fullWidth={true}
value={this.state.record.quantity}
inputProps={{source: "quantity"}}
onChange={this.handleTextInputChange}
/>
</Grid>
<Grid item sm={4} xs={12}>
<label>Cost</label><br />
<TextField
id="cost"
fullWidth={true}
value={this.state.record.cost}
inputProps={{source: "cost"}}
onChange={this.handleTextInputChange}
/>
</Grid>
<Grid item sm={4} xs={12}>
<label>Amount</label><br />
<TextField
id="amount"
fullWidth={true}
value={this.state.record.amount}
inputProps={{source: "amount"}}
disabled={true}
onChange={this.handleTextInputChange}
/>
</Grid>
</Grid>
</form>
);
}
How can we accomplish this with react-admin?

Appcelerator Dynamic TableViewRow title only appears after scroll

I am developing an App and I have a tableview that load data from an API, and render the tableviewrows from an external file.
When the screen opens, the tableview is blank, but If I scroll up the tableview, I can see the title in the firts rows.
Can you help me? Thanks!
categorias.xml
<Alloy>
<Window class="container">
<View class="titleBar">
<Button id="backButton" onClick="backWindow" />
<Label class="lblTitle">Categorias</Label>
<Button id="nextButton" onClick="create" TipoAtributoId="0">Novo</Button>
</View>
<TableView id="tblData" top="70" editable="true" deleteButtonTitle="Apagar">
</TableView>
</Window>
</Alloy>
categoria.js
function getCategoria(){
var rows = [];
net.categoriaGet(function(data){
$.tblData.data = [];
if (data != null){
for (var i=0; i < data.length; i++){
var arg = {
type:'categoria',
title: data[i].Nome,
id: data[i].CategoriaId
};
rows.push(Alloy.createController('row', arg).getView());
}
$.tblData.setData(rows);
Alloy.Globals.hideIndicator();
rc.endRefreshing();
} else {
Alloy.Globals.hideIndicator();
rc.endRefreshing();
}
});
}
row.xml
<Alloy>
<TableViewRow id="rowView" onClick="edit"/>
</Alloy>
row.js
var args = $.args;
$.rowView.title = $.args.title;
initial screenscreen after scroll to up

Xamarin Forms Navigation page searchbar entries unable to write

I have two pages MainPage and SecondPage1 .in App.xaml.cs I Navigate to Secondpage1 using this code:
App.xaml.cs :
//MainPage = new Fmkt44Application.MainPage();/*First Approach*/
MainPage = new NavigationPage(new MainPage());/*Second approach*/
MainPage.xaml.cs:
// App.Current.MainPage = new NavigationPage(new SecondPage1());/*First Approach*/
await Navigation.PushAsync(new SecondPage1());/*Second approach*/
Problem is if I use both approaches I can navigate to secondpage1 but if I use second approach I cant write on searchbar or any entries. What is the reason and how can I Fix it?
Here is MainPage.xaml.cs
namespace Fmkt44Application
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
public async System.Threading.Tasks.Task LoginControlAsync(Object sender, EventArgs args)
{
User.UserName = entry_user.Text;
User.Password = entry_passw.Text;
if (User.CheckUserInformation() == false)
{
DisplayAlert("Login", "Kullanıcı Adını veya şifresini giriniz", "OK");
}
else
{
String val = entry_user.Text + "$" + entry_passw.Text;
CallIasWebService.Login();
String rval = CallIasWebService.CallIASService("PROFILECONTROL", val);
CallIasWebService.Logout();
User.Profile = rval.ToString();
if (rval != "0" )
{
if (User.Profile != "" && User.Profile != null)
{
// App.Current.MainPage = new NavigationPage(new SecondPage1());if I Call Like this I can write on Secondpage1 (First approach)
await Navigation.PushAsync(new SecondPage1());/*I cannot reach SecondPage1 controls/* (second approach)*/
}
else
{
DisplayAlert("Login", "Kayıt yapma yetkiniz yoktur.", "OK");
}
}
else
{
DisplayAlert("Login", "Kullanıcı Adını veya şifresi hatalıdır.", "OK");
}
}
}
public async System.Threading.Tasks.Task scanncontrolAsync(Object sender, EventArgs E)
{
// await Navigation.PushAsync(new SecondPage1());
App.Current.MainPage = new SecondPage1();
}
}
}
App.cs is
public App ()
{
InitializeComponent();
//MainPage = new Fmkt44Application.MainPage();(First apploach)
MainPage = new NavigationPage(new MainPage());/*second approach*/
}
Secondpage1.xaml is
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Fmkt44Application.SecondPage1">
<ContentPage.Content>
<StackLayout>
<SearchBar Placeholder="Ara..." TextChanged="TextChange" x:Name="searchbar" />
<ListView x:Name="Materials" ItemTapped="MakineSec" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<StackLayout Orientation="Horizontal" >
<Label Text="{Binding Material}"/>
<Label Text="{Binding Stext}"/>
</StackLayout>
<Entry Text="{Binding SerialNumber}" />
</StackLayout>
<ViewCell.ContextActions>
<MenuItem Text="Seç" Clicked="MakineSec" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
Problem comes from Android Emulator. I tried a real tablet problem solved.

How can I set up binding context in XAML to a different class?

I've got this code I'm trying to bind to a class named BandInfoRepository.cs which is located in the same folder as this XAML named PaginaB.I can't see no syntax error displayed on VisualStudio, still the text is not showing(I added backgroundColor just to see if the label was being displayed and they are, but the text isn't).
Maybe it's important to point out I'm using syncfusion's listview.
PaginaB.xaml :
<syncfusion:SfListView x:Name="listView"
ItemsSource="{Binding Source={local2:BandInfoRepository}, Path=BandInfo}"
ItemSize="100"
AbsoluteLayout.LayoutBounds="1,1,1,1"
AbsoluteLayout.LayoutFlags="All" >
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="0.4*" />
<RowDefinition Height="0.6*" />
</Grid.RowDefinitions>
<Label Text="{Binding Source={local2:BandInfoRepository}, Path=BandName}"
BackgroundColor="Olive"
FontAttributes="Bold"
TextColor="Black"
FontSize="20" />
<Label Grid.Row="1"
BackgroundColor="Navy"
Text="{Binding Source={local2:BandInfoRepository}, Path= BandDescription}"
TextColor="Black"
FontSize="14"/>
</Grid>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
And this is the BandInfoRepository.cs file:
public class BandInfoRepository
{
private ObservableCollection<BandInfo> bandInfo;
public ObservableCollection<BandInfo> BandInfo
{
get { return bandInfo; }
set { this.bandInfo = value; }
}
public BandInfoRepository()
{
GenerateBookInfo();
}
internal void GenerateBookInfo()
{
bandInfo = new ObservableCollection<BandInfo>();
bandInfo.Add(new BandInfo() { BandName = "Nirvana", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Metallica", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Frank Sinatra", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "B.B. King", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Iron Maiden", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Megadeth", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Darude", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Coldplay", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Dream Evil", BandDescription = "description" });
bandInfo.Add(new BandInfo() { BandName = "Pentakill", BandDescription = "description" });
}
}
In your DataTemplate you don't set Source in binding normally, unless you want to do some magic. XAML sets DataContext to each item of ItemsSource.
Try:
<Label Text="{Binding BandName}" BackgroundColor="Olive" FontAttributes="Bold" />
and remember to implement INotifyPropertyChanged for BandInfo if you want XAML to track changes in its properties
Thank you for using Syncfusion Products.
We looked into you code and found that you have defined the ItemTemplate wrongly. You can bind the data objects in the underlying collection directly into the view defined in the ItemTemplate property. SfListView itself creates a view for each items in the ItemsSource property and defines the binding context to it.
For your reference, we have attached the sample and you can download it from the below link.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/ListViewSample607957192
For more information about working with SfListView, please refer the following UG documentation link.
https://help.syncfusion.com/xamarin/sflistview/getting-started
Please let us know if you require further assistance.
Regards,
Dinesh Babu Yadav