我有listview一个按钮(默认内容==“添加”)和1个文本框。在列表视图上双击事件按钮。内容==“编辑”和文本框填充列表视图中的信息。
如果声明无效,
if (btnAddFloor.Content == "Add")
{
HProDataContext db = new HProDataContext();
floor f = new floor { floorname = txtFloorName.Text };
db.floors.InsertOnSubmit(f);
db.SubmitChanges();
RefreshListViewFloor();
}
else
{
int currentID = Convert.ToInt32(listViewFloors.SelectedValue);
HProDataContext db = new HProDataContext();
floor f = db.floors.Single(p => p.id == currentID);
f.floorname = txtFloorName.Text;
db.SubmitChanges();
RefreshListViewFloor();
txtFloorName.Text = null;
RefreshListViewRoom();
}
和btnAddFloor.Content ==“添加”是绿色下划线 有谁可以帮助我?
XAML
<GroupBox Header="Floors" Height="287" HorizontalAlignment="Left" Margin="12,32,0,0" Name="GroupBoxFloors" VerticalAlignment="Top" Width="342">
<Grid>
<Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="169,37,0,0" Name="btnAddFloor" VerticalAlignment="Top" Width="75" Click="btnAddFloor_Click" />
<ListView Height="192" HorizontalAlignment="Left" Margin="6,66,0,0" Name="listViewFloors" VerticalAlignment="Top" Width="318" ItemsSource="{Binding FloorCollection}" SelectedValuePath="ID" MouseDoubleClick="listViewFloors_MouseDoubleClick">
<ListView.View >
<GridView>
<GridViewColumn Header="ID" Width="60" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Header="FloorName" Width="200" DisplayMemberBinding="{Binding FloorName}"/>
</GridView>
</ListView.View>
</ListView>
<TextBox Height="23" HorizontalAlignment="Left" Margin="6,37,0,0" Name="txtFloorName" VerticalAlignment="Top" Width="157" TextChanged="txtFloorName_TextChanged" />
<Button Content="Remove" Height="23" HorizontalAlignment="Left" Margin="249,37,0,0" Name="btnRemoveFloor" VerticalAlignment="Top" Width="75" Click="btnRemoveFloor_Click" />
<Label Content="Floor Name" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</GroupBox>
答案 0 :(得分:4)
Button.Content的类型为Object,使用“==”运算符会比较指针。 你想要做的是:
btnAddFloor.Content.ToString()==“添加”